import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:yumi/app_localizations.dart';
import 'package:provider/provider.dart';

import 'package:yumi/ui_kit/components/appbar/socialchat_appbar.dart';
import 'package:yumi/ui_kit/components/text/sc_text.dart';
import 'package:yumi/shared/data_sources/sources/local/data_persistence.dart';
import 'package:yumi/services/localization/localization_manager.dart';
import 'package:yumi/app/constants/sc_global_config.dart';

///语言选择
class LanguagePage extends StatefulWidget {
  @override
  _LanguagePageState createState() => _LanguagePageState();
}

class _LanguagePageState extends State<LanguagePage> {
  int selectType = 1;

  @override
  void initState() {
    super.initState();
    String langCode = DataPersistence.getLang();
    if (langCode == "ar") {
      selectType = 1;
    }else if(langCode == "tr"){
      selectType = 2;
    }else if(langCode == "bn"){
      selectType = 3;
    } else {
      selectType = 0;
    }
  }

  @override
  Widget build(BuildContext context) {
    return Stack(
      children: [
        Image.asset(
          SCGlobalConfig.businessLogicStrategy.getLanguagePageBackgroundImage(),
          width: ScreenUtil().screenWidth,
          height: ScreenUtil().screenHeight,
          fit: BoxFit.fill,
        ),
        Scaffold(
          backgroundColor: SCGlobalConfig.businessLogicStrategy.getLanguagePageScaffoldBackgroundColor(),
          resizeToAvoidBottomInset: false,
          appBar: SocialChatStandardAppBar(
            title: SCAppLocalizations.of(context)!.language,
            actions: [],
          ),
          body: Column(
            children: [
              Row(
                children: [
                  SizedBox(width: 15.w),
                  Expanded(
                    child: text(
                      "English",
                      textColor: SCGlobalConfig.businessLogicStrategy.getLanguagePagePrimaryTextColor(),
                      fontSize: 15.sp,
                    ),
                  ),
                  Checkbox(
                    value: selectType == 0,
                    checkColor: SCGlobalConfig.businessLogicStrategy.getLanguagePageCheckColor(),
                    activeColor: SCGlobalConfig.businessLogicStrategy.getLanguagePageCheckboxActiveColor(),
                    onChanged: (b) {
                      if (selectType == 0) {
                        selectType = 1;
                      } else {
                        selectType = 0;
                      }
                      setState(() {});
                      if (b!) {
                        Provider.of<LocalizationManager>(
                          context,
                          listen: false,
                        ).changeAppLanguage(const Locale('en', ''));
                      }
                    },
                    shape: RoundedRectangleBorder(
                      borderRadius: BorderRadius.circular(SCGlobalConfig.businessLogicStrategy.getLanguagePageCheckboxBorderRadius()),
                    ),
                    side: WidgetStateBorderSide.resolveWith((states) {
                      if (states.contains(WidgetState.selected)) {
                        return BorderSide(
                          color: SCGlobalConfig.businessLogicStrategy.getLanguagePageCheckboxBorderColor(),
                          width: SCGlobalConfig.businessLogicStrategy.getLanguagePageCheckboxBorderWidth(),
                        ); // 选中时保留蓝色边框
                      }
                      return BorderSide(
                        color: SCGlobalConfig.businessLogicStrategy.getLanguagePageCheckboxBorderColor(),
                        width: SCGlobalConfig.businessLogicStrategy.getLanguagePageCheckboxBorderWidth(),
                      ); // 未选中时灰色边框
                    }),
                  ),
                ],
              ),
              Row(
                children: [
                  SizedBox(width: 15.w),
                  Expanded(
                    child: text(
                      "العربية",
                      textColor: SCGlobalConfig.businessLogicStrategy.getLanguagePagePrimaryTextColor(),
                      fontSize: 15.sp,
                    ),
                  ),
                  Checkbox(
                    value: selectType == 1,
                    checkColor: SCGlobalConfig.businessLogicStrategy.getLanguagePageCheckColor(),
                    activeColor: SCGlobalConfig.businessLogicStrategy.getLanguagePageCheckboxActiveColor(),
                    onChanged: (b) {
                      if (selectType == 1) {
                        selectType = 0;
                      } else {
                        selectType = 1;
                      }
                      setState(() {});
                      if (b!) {
                        Provider.of<LocalizationManager>(
                          context,
                          listen: false,
                        ).changeAppLanguage(const Locale('ar', ''));
                      }
                    },
                    shape: RoundedRectangleBorder(
                      borderRadius: BorderRadius.circular(SCGlobalConfig.businessLogicStrategy.getLanguagePageCheckboxBorderRadius()),
                    ),
                    side: WidgetStateBorderSide.resolveWith((states) {
                      if (states.contains(WidgetState.selected)) {
                        return BorderSide(
                          color: SCGlobalConfig.businessLogicStrategy.getLanguagePageCheckboxBorderColor(),
                          width: SCGlobalConfig.businessLogicStrategy.getLanguagePageCheckboxBorderWidth(),
                        ); // 选中时保留蓝色边框
                      }
                      return BorderSide(
                        color: SCGlobalConfig.businessLogicStrategy.getLanguagePageCheckboxBorderColor(),
                        width: SCGlobalConfig.businessLogicStrategy.getLanguagePageCheckboxBorderWidth(),
                      ); // 未选中时灰色边框
                    }),
                  ),
                ],
              ),
              Row(
                children: [
                  SizedBox(width: 15.w),
                  Expanded(
                    child: text(
                      "Türkçe",
                      textColor: SCGlobalConfig.businessLogicStrategy.getLanguagePagePrimaryTextColor(),
                      fontSize: 15.sp,
                    ),
                  ),
                  Checkbox(
                    value: selectType == 2,
                    checkColor: SCGlobalConfig.businessLogicStrategy.getLanguagePageCheckColor(),
                    activeColor: SCGlobalConfig.businessLogicStrategy.getLanguagePageCheckboxActiveColor(),
                    onChanged: (b) {
                      if (selectType == 2) {
                        selectType = 0;
                      } else {
                        selectType = 2;
                      }
                      setState(() {});
                      if (b!) {
                        Provider.of<LocalizationManager>(
                          context,
                          listen: false,
                        ).changeAppLanguage(const Locale('tr', ''));
                      }
                    },
                    shape: RoundedRectangleBorder(
                      borderRadius: BorderRadius.circular(SCGlobalConfig.businessLogicStrategy.getLanguagePageCheckboxBorderRadius()),
                    ),
                    side: WidgetStateBorderSide.resolveWith((states) {
                      if (states.contains(WidgetState.selected)) {
                        return BorderSide(
                          color: SCGlobalConfig.businessLogicStrategy.getLanguagePageCheckboxBorderColor(),
                          width: SCGlobalConfig.businessLogicStrategy.getLanguagePageCheckboxBorderWidth(),
                        ); // 选中时保留蓝色边框
                      }
                      return BorderSide(
                        color: SCGlobalConfig.businessLogicStrategy.getLanguagePageCheckboxBorderColor(),
                        width: SCGlobalConfig.businessLogicStrategy.getLanguagePageCheckboxBorderWidth(),
                      ); // 未选中时灰色边框
                    }),
                  ),
                ],
              ),              Row(
                children: [
                  SizedBox(width: 15.w),
                  Expanded(
                    child: text(
                      "বাংলা",
                      textColor: SCGlobalConfig.businessLogicStrategy.getLanguagePagePrimaryTextColor(),
                      fontSize: 15.sp,
                    ),
                  ),
                  Checkbox(
                    value: selectType == 3,
                    checkColor: SCGlobalConfig.businessLogicStrategy.getLanguagePageCheckColor(),
                    activeColor: SCGlobalConfig.businessLogicStrategy.getLanguagePageCheckboxActiveColor(),
                    onChanged: (b) {
                      if (selectType == 3) {
                        selectType = 0;
                      } else {
                        selectType = 3;
                      }
                      setState(() {});
                      if (b!) {
                        Provider.of<LocalizationManager>(
                          context,
                          listen: false,
                        ).changeAppLanguage(const Locale('bn', ''));
                      }
                    },
                    shape: RoundedRectangleBorder(
                      borderRadius: BorderRadius.circular(SCGlobalConfig.businessLogicStrategy.getLanguagePageCheckboxBorderRadius()),
                    ),
                    side: WidgetStateBorderSide.resolveWith((states) {
                      if (states.contains(WidgetState.selected)) {
                        return BorderSide(
                          color: SCGlobalConfig.businessLogicStrategy.getLanguagePageCheckboxBorderColor(),
                          width: SCGlobalConfig.businessLogicStrategy.getLanguagePageCheckboxBorderWidth(),
                        ); // 选中时保留蓝色边框
                      }
                      return BorderSide(
                        color: SCGlobalConfig.businessLogicStrategy.getLanguagePageCheckboxBorderColor(),
                        width: SCGlobalConfig.businessLogicStrategy.getLanguagePageCheckboxBorderWidth(),
                      ); // 未选中时灰色边框
                    }),
                  ),
                ],
              ),
            ],
          ),
        ),
      ],
    );
  }
}
