import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:gap/gap.dart';
import 'package:tanami_app/core/routes/routes.dart';
import 'package:tanami_app/core/styles/app_color.dart';
import 'package:tanami_app/core/utils/secure/secure_storage_service.dart';
import 'package:tanami_app/features/welcome/presentation/pages/weclome_screen.dart';
import 'package:tanami_app/shared/components/text_widget.dart';

import '../../Globalconst.dart';
import 'bloc/language/lng_bloc.dart';
import 'bloc/language/lng_event.dart';

void showLanguageBottomSheet(BuildContext context) {
  final SharedPreferenceLocalData secureStorageService =
      SharedPreferenceLocalData();
  showModalBottomSheet(
    backgroundColor: Colors.transparent,
    context: context,
    builder: (BuildContext context) {
      return Padding(
        padding: const EdgeInsets.all(8.0),
        child: Column(
          mainAxisSize: MainAxisSize.min,
          children: [
            Container(
              width: 1.sw,
              height: 168.7.h,
              decoration: BoxDecoration(
                  borderRadius: BorderRadius.circular(12),
                  color: Colors.black87),
              child: Column(
                children: [
                  const Gap(10),
                  Center(
                    child: TextWidget()
                        .text17W700("Language", clr: Colors.white60),
                  ),
                  const Gap(10),
                  const Divider(
                    color: AppColor.plainWhite,
                  ),
                  const Gap(10),
                  InkWell(
                    onTap: () async {
                      context
                          .read<LocalizationBloc>()
                          .add(const ChangeLanguage(Locale('en')));

                      await secureStorageService.write(
                          'languageSelected', "en");
                      goRouter.pop();
                      Globalconst.languageSelected = "en";
                      Navigator.of(context).push(MaterialPageRoute(
                          builder: (_) => const WelcomeScreen()));
                    },
                    child: Center(
                      child:
                          TextWidget().text15W700("English", clr: Colors.white),
                    ),
                  ),
                  const Gap(10),
                  const Divider(
                    color: AppColor.plainWhite,
                  ),
                  const Gap(10),
                  InkWell(
                    onTap: () async {
                      context
                          .read<LocalizationBloc>()
                          .add(const ChangeLanguage(Locale('ar')));
                      Globalconst.languageSelected = "ar";
                      await secureStorageService.write(
                          'languageSelected', "ar");
                      goRouter.pop();
                      Navigator.of(context).push(MaterialPageRoute(
                          builder: (_) => const WelcomeScreen()));
                    },
                    child: Center(
                      child: TextWidget().text15W700("عربي", clr: Colors.white),
                    ),
                  ),
                  const Gap(20),
                ],
              ),
            ),
            const Gap(18),
            GestureDetector(
              onTap: () {
                goRouter.pop();
              },
              child: Container(
                width: 1.sw,
                height: 56.h,
                decoration: BoxDecoration(
                    borderRadius: BorderRadius.circular(12),
                    color: Colors.black87),
                child: Center(
                  child:
                      TextWidget().text14W500("Dismiss", clr: Colors.white60),
                ),
              ),
            ),
            const Gap(18),
          ],
        ),
      );
    },
  );
}
