import 'package:flutter/material.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/theme/colors.dart';
import 'package:mc_common_app/utils/enums.dart';
import 'package:mc_common_app/utils/navigator.dart';
import 'package:mc_common_app/view_models/setting_options_view_model.dart';
import 'package:mc_common_app/views/setting_options/widgets/custom_setting_options_tile.dart';
import 'package:mc_common_app/widgets/common_widgets/app_bar.dart';
import 'package:mc_common_app/widgets/common_widgets/info_bottom_sheet.dart';
import 'package:mc_common_app/widgets/extensions/extensions_widget.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:provider/provider.dart';

class SettingOptionsInviteFriends extends StatelessWidget {
  const SettingOptionsInviteFriends({super.key});

  buildInviteFriendsBottomSheet(BuildContext context) {
    return showModalBottomSheet(
      context: context,
      isScrollControlled: true,
      enableDrag: true,
      builder: (BuildContext context) {
        return InfoBottomSheet(
          title: LocaleKeys.inviteFriends.tr().toText(fontSize: 28, isBold: true, letterSpacing: -1.44),
          description: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              CustomSettingOptionsTile(
                leadingWidget: MyAssets.whatsAppIcon.buildSvg(
                  height: 20,
                  width: 20,
                  color: MyColors.greyColor,
                ),
                titleText: LocaleKeys.inviteFriendsByWhatsApp.tr(),
                needBorderBelow: true,
                showTrailingArrow: false,
                onTap: () async {
                  await context.read<SettingOptionsVM>().appInvitationCreate(context: context, channelId: 1);
                },
              ),
              CustomSettingOptionsTile(
                  leadingWidget: const Icon(
                    Icons.sms_outlined,
                    size: 20,
                    color: MyColors.greyColor,
                  ),
                  titleText: LocaleKeys.inviteFriendsBySMS.tr(),
                  needBorderBelow: true,
                  showTrailingArrow: false,
                  onTap: () async {
                    await context.read<SettingOptionsVM>().appInvitationCreate(context: context, channelId: 2);
                  }),
              CustomSettingOptionsTile(
                leadingWidget: const Icon(
                  Icons.email_outlined,
                  size: 20,
                  color: MyColors.greyColor,
                ),
                titleText: LocaleKeys.inviteFriendsByEmail.tr(),
                needBorderBelow: false,
                showTrailingArrow: false,
                onTap: () async {
                  await context.read<SettingOptionsVM>().appInvitationCreate(context: context, channelId: 3);
                },
              ),
              30.height,
            ],
          ),
        );
      },
    );
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: CustomAppBar(
        title: LocaleKeys.settings.tr(),
        isRemoveBackButton: false,
        isDrawerEnabled: false,
        onBackButtonTapped: () => Navigator.pop(context),
      ),
      body: Column(
        children: [
          Expanded(
            child: ListView(
              children: [
                Column(
                  children: [
                    if (AppState().currentAppType == AppType.customer) ...[
                      CustomSettingOptionsTile(
                        leadingWidget: const Icon(Icons.group, size: 20),
                        titleText: LocaleKeys.inviteFriends.tr(),
                        needBorderBelow: true,
                        onTap: () {
                          return buildInviteFriendsBottomSheet(context);
                        },
                      ),
                    ],
                    CustomSettingOptionsTile(
                      leadingWidget: const Icon(Icons.question_mark_outlined, size: 20),
                      titleText: LocaleKeys.help.tr(),
                      needBorderBelow: true,
                      onTap: () => navigateWithName(context, AppRoutes.settingOptionsHelp),
                    ),
                    CustomSettingOptionsTile(
                        leadingWidget: const Icon(Icons.person, size: 20),
                        titleText: LocaleKeys.account.tr(),
                        needBorderBelow: false,
                        onTap: () {
                          navigateWithName(context, AppRoutes.profileView);
                        }),
                  ],
                ).toContainer(
                  width: double.infinity,
                  isShadowEnabled: true,
                  paddingAll: 10,
                  margin: const EdgeInsets.fromLTRB(21, 21, 21, 0),
                  borderRadius: 0,
                ),
              ],
            ),
          ),
        ],
      ),
    );
  }
}
