import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:mc_common_app/classes/app_state.dart';
import 'package:mc_common_app/classes/consts.dart';
import 'package:mc_common_app/config/routes.dart';
import 'package:mc_common_app/extensions/int_extensions.dart';
import 'package:mc_common_app/extensions/string_extensions.dart';
import 'package:mc_common_app/generated/locale_keys.g.dart';
import 'package:mc_common_app/main.dart';
import 'package:mc_common_app/theme/colors.dart';
import 'package:mc_common_app/utils/dialogs_and_bottomsheets.dart';
import 'package:mc_common_app/utils/enums.dart';
import 'package:mc_common_app/utils/navigator.dart';
import 'package:mc_common_app/view_models/user_view_model.dart';
import 'package:mc_common_app/views/setting_options/widgets/custom_setting_options_tile.dart';
import 'package:mc_common_app/widgets/button/show_fill_button.dart';
import 'package:mc_common_app/widgets/common_widgets/app_bar.dart';
import 'package:mc_common_app/widgets/extensions/extensions_widget.dart';
import 'package:provider/provider.dart';

class SettingOptionsMore extends StatefulWidget {
  const SettingOptionsMore({super.key});

  @override
  State<SettingOptionsMore> createState() => _SettingOptionsMoreState();
}

class _SettingOptionsMoreState extends State<SettingOptionsMore> {
  void logoutConfirmationSheet(BuildContext context) {
    return actionConfirmationBottomSheet(
      context: context,
      title: LocaleKeys.logoutConfirmation.tr().toText(fontSize: 28, isBold: true, letterSpacing: -1.44),
      subtitle: LocaleKeys.logoutConfirmationMessage.tr(),
      actionButtonYes: Expanded(
        child: ShowFillButton(
          maxHeight: 55,
          title: LocaleKeys.yes.tr(),
          fontSize: 15,
          onPressed: () {
            Navigator.pop(context);
            context.read<UserVM>().logout(context);
          },
        ),
      ),
      actionButtonNo: Expanded(
        child: ShowFillButton(
          maxHeight: 55,
          isFilled: false,
          borderColor: MyColors.darkPrimaryColor,
          title: LocaleKeys.no.tr(),
          txtColor: MyColors.darkPrimaryColor,
          fontSize: 15,
          onPressed: () {
            Navigator.pop(context);
          },
        ),
      ),
    );
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: CustomAppBar(
        title: LocaleKeys.more.tr(),
        isRemoveBackButton: false,
        isDrawerEnabled: false,
        onBackButtonTapped: () => Navigator.pop(context),
      ),
      body: Column(
        children: [
          //    (AppState().currentAppType == AppType.provider)
          //       ?
          Expanded(
              child: ListView(
            shrinkWrap: true,
            padding: EdgeInsets.zero,
            children: [
              Column(
                children: [
                  if (AppState().currentAppType == AppType.customer) ...[
                    CustomSettingOptionsTile(
                      leadingWidget: const Icon(Icons.favorite, size: 20),
                      titleText: LocaleKeys.favoriteList.tr(),
                      needBorderBelow: true,
                      onTap: () => navigateWithName(context, AppRoutes.favoriteListView),
                    ),
                  ] else ...[
                    CustomSettingOptionsTile(
                      leadingWidget: SvgPicture.asset(
                        MyAssets.icRequests,
                        height: 20,
                        width: 20,
                        color: MyColors.darkIconColor,
                      ),
                      titleText: LocaleKeys.acceptedRequests.tr(),
                      needBorderBelow: true,
                      onTap: () {
                        navigateWithName(context, AppRoutes.providerAcceptedRequestsView);
                      },
                    ),
                    CustomSettingOptionsTile(
                      leadingWidget: const Icon(Icons.local_shipping, size: 20),
                      titleText: LocaleKeys.shippingManagement.tr(),
                      needBorderBelow: true,
                      onTap: () {
                        navigateWithName(context, AppRoutes.shippingManagementView);
                      },
                    ),
                  ],
                  CustomSettingOptionsTile(
                    leadingWidget: const Icon(Icons.settings, size: 20),
                    titleText: LocaleKeys.settings.tr(),
                    needBorderBelow: false,
                    onTap: () => navigateWithName(context, AppRoutes.settingOptionsInviteFriends),
                  ),
                ],
              ).toWhiteContainer(width: double.infinity, pading: const EdgeInsets.all(12), borderRadius: 0),
              10.height,
              if (!disableThingsForQA) ...[
                CustomSettingOptionsTile(
                  leadingWidget: const Icon(Icons.translate, size: 20),
                  titleText: LocaleKeys.language.tr(),
                  isForLanguage: true,
                  onTap: () {
                    context.read<UserVM>().changeLanguage(context);
                    Future.delayed(const Duration(seconds: 1), () {
                      setState(() {});
                    });
                  },
                ).toWhiteContainer(width: double.infinity, pading: const EdgeInsets.all(12), borderRadius: 0),
                10.height,
              ],
              (AppState().currentAppType == AppType.provider)
                  ? Column(
                      children: [
                        CustomSettingOptionsTile(
                          leadingWidget: SizedBox(
                            width: 16,
                            height: 16,
                            child: SvgPicture.asset(
                              MyAssets.icStar,
                              color: MyColors.primaryColor,
                            ),
                          ),
                          titleText: LocaleKeys.mySubscription.tr(),
                          subTitle: AppState().getproviderSubscription.isNotEmpty ? (AppState().getproviderSubscription.first.name ?? "") : "",
                          isForLanguage: false,
                          needBorderBelow: true,
                          onTap: () {
                            navigateWithName(context, AppRoutes.mySubscriptionsPage);
                          },
                        ),
                        CustomSettingOptionsTile(
                          leadingWidget: SizedBox(
                            width: 16,
                            height: 16,
                            child: SvgPicture.asset(MyAssets.icGroupStar),
                          ),
                          titleText: LocaleKeys.subscriptions.tr(),
                          subTitle: null,
                          isForLanguage: false,
                          needBorderBelow: true,
                          onTap: () {
                            navigateWithName(context, AppRoutes.subscriptionsPage);
                          },
                        ),
                        CustomSettingOptionsTile(
                          leadingWidget: SizedBox(
                            width: 16,
                            height: 16,
                            child: SvgPicture.asset(
                              MyAssets.icGroupStar,
                              // color: MyColors.primaryColor,
                            ),
                          ),
                          titleText: LocaleKeys.defineLicenses.tr(),
                          subTitle: null,
                          isForLanguage: false,
                          needBorderBelow: false,
                          onTap: () {
                            navigateWithName(context, AppRoutes.providerLicensePage);
                          },
                        ),
                        // CustomSettingOptionsTile(
                        //   leadingWidget: SizedBox(
                        //     width: 16,
                        //     height: 16,
                        //     child: SvgPicture.asset(
                        //       MyAssets.providersIcon,
                        //       // color: MyColors.primaryColor,
                        //     ),
                        //   ),
                        //   titleText: "Users",
                        //   subTitle: null,
                        //   isForLanguage: false,
                        //   needBorderBelow: false,
                        //   onTap: () {
                        //     navigateWithName(context, AppRoutes.dealerUser, arguments: AppState().getUser.data!.userInfo!.id.toString());
                        //   },
                        // )
                      ],
                    ).toWhiteContainer(width: double.infinity, pading: const EdgeInsets.all(12), borderRadius: 0)
                  : const SizedBox(),
              (AppState().currentAppType == AppType.provider) ? 10.height : const SizedBox(),
            ],
          )),
          // : Expanded(
          //     child: ListView(
          //       children: [
          //         Column(
          //           children: [
          //             CustomSettingOptionsTile(
          //                 leadingWidget: const Icon(Icons.person, size: 20),
          //                 titleText: "My Requests",
          //                 needBorderBelow: true,
          //                 onTap: () {
          //                   context.read<BaseVM>().onNavbarTapped(4);
          //                   Navigator.pop(context);
          //                 }),
          //             CustomSettingOptionsTile(leadingWidget: const Icon(Icons.favorite, size: 20), titleText: "Favorite list", needBorderBelow: true, onTap: () {}),
          //             CustomSettingOptionsTile(
          //                 leadingWidget: const Icon(Icons.settings, size: 20), titleText: "Settings", onTap: () => navigateWithName(context, AppRoutes.settingOptionsInviteFriends)),
          //           ],
          //         ).toContainer(width: double.infinity, isShadowEnabled: true, paddingAll: 10, margin: const EdgeInsets.fromLTRB(24, 24, 24, 0), borderRadius: 0),
          //         CustomSettingOptionsTile(leadingWidget: const Icon(Icons.translate, size: 20), titleText: "Language", isForLanguage: true, onTap: () {})
          //             .toContainer(width: double.infinity, isShadowEnabled: true, paddingAll: 10, marginAll: 21, borderRadius: 0),
          //       ],
          //     ),
          //   ),
          Row(
            children: [
              Expanded(
                child: ShowFillButton(
                  borderColor: MyColors.redColor,
                  txtColor: MyColors.redColor,
                  isFilled: false,
                  fontSize: 16,
                  maxHeight: 55,
                  title: LocaleKeys.logOut.tr(),
                  onPressed: () {
                    logoutConfirmationSheet(context);
                  },
                ),
              ),
            ],
          ).paddingAll(0),
        ],
      ).paddingAll(21),
    );
  }
}
