import 'package:flutter/material.dart';
import 'package:flutter_wallet/base/YSBase.dart';
import 'package:flutter_wallet/generated/l10n.dart';
import 'package:flutter_wallet/tools/YSColors.dart';
import 'package:flutter_wallet/tools/YSLoadData.dart';
import 'package:flutter_wallet/tools/YSTools.dart';

class YSSettingLanguage extends StatefulWidget {
  const YSSettingLanguage({Key? key}) : super(key: key);

  @override
  YSSettingLanguageState createState() => YSSettingLanguageState();
}

class YSSettingLanguageState extends State<YSSettingLanguage> {
  final List _list = [
    {'title':'中文','type':'zh'},
    {'title':'English','type':'en'},
    {'title':'日本語','type':'ja'},
    {'title':'Русский','type':'ru'},
    {'title':'Français','type':'fr'},
    {'title':'한국인','type':'ko'}
  ];
  @override
  Widget build(BuildContext context) {
    return YSBase(
      ysTitle: S.current.YUYANSHEZHI,
      ysChild: Container(
        width: ysWidth(context),
        color: YSColors.containColor(context),
        child: ListView.separated(
          itemBuilder: (context,index){
            Map item = _list[index];
            bool isChoose = item['type']==YSUserRecord().language;
            return GestureDetector(
              onTap: (){
                setState(() {
                  YSUserRecord().language = item['type'];
                });
                YSLanguage().changeLanguage(context, item['type']);
                YSSharedPreferences.setStringValue('language', item['type']);
              },
              behavior: HitTestBehavior.opaque,
              child: Padding(
                padding: EdgeInsets.only(top: hsp(15),bottom: hsp(15)),
                child: Row(
                  children: [
                    Expanded(child: Text(item['title'],style: YSColors.contentStyle(context),)),
                    if(isChoose)Icon(Icons.check_circle,size: hsp(20),color: YSColors.iconColor(context),)
                  ],
                ),
              ),
            );
          },
          separatorBuilder: (context,index){
            return Divider(height: hsp(1),color: YSColors.lineColor(context),);
          },
          itemCount: _list.length,
          shrinkWrap: true,
          physics: const NeverScrollableScrollPhysics(),
          padding: EdgeInsets.only(left: hsp(15),right: hsp(15)),
        ),
      ),
    );
  }
}
