import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:provider/provider.dart';
import 'package:test_sa/controllers/providers/api/user_provider.dart';
import 'package:test_sa/extensions/widget_extensions.dart';
import 'package:test_sa/new_views/swipe_module/dialoge/confirm_dialog.dart';

import '../controllers/providers/settings/setting_provider.dart';

extension BuildContextExtension on BuildContext {
  AppLocalizations get translation => AppLocalizations.of(this)!;

  List<String> get getIssues => [translation.reason1, translation.reason2, translation.reason3, translation.reason4, translation.reason5];

  bool get isDark => Provider.of<SettingProvider>(this).theme == "dark";

  bool get isAr => Provider.of<SettingProvider>(this).language == "ar";

  SettingProvider get settingProvider => Provider.of<SettingProvider>(this, listen: false);

  UserProvider get userProvider => Provider.of<UserProvider>(this, listen: false);
  bool isTablet() {
    final mediaQueryData = MediaQuery.of(this);
    final double screenWidth = mediaQueryData.size.width;
    final double screenHeight = mediaQueryData.size.height;
    final double devicePixelRatio = mediaQueryData.devicePixelRatio;
    bool isTablet = (devicePixelRatio < 2 && (screenWidth >= 700 || screenHeight >= 700)) || (devicePixelRatio >= 2 && (screenWidth >= 1000 || screenHeight >= 1000));
    return isTablet;
  }
  void showConfirmDialog(String message, {String? title, VoidCallback? onTap}) => showDialog(
        context: this,
        builder: (BuildContext cxt) => ConfirmDialog(message: message, onTap: onTap, title: title),
      );

  Future showBottomSheet(Widget childWidget, {bool? isDismissible, String? title}) => showModalBottomSheet(
        context: this,
        useSafeArea: true,
        isScrollControlled: true,
        isDismissible: true,
        backgroundColor: Colors.transparent,
        builder: (context) => SingleChildScrollView(padding: const EdgeInsets.all(0), child: childWidget.bottomSafeArea).bottomSheetContainerNew(context, title: title),
      );
}
