import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_wallet/generated/l10n.dart';
import 'package:flutter_wallet/setting/YSAboutUs.dart';
import 'package:flutter_wallet/setting/YSAlwayAddress.dart';
import 'package:flutter_wallet/setting/YSSettingSystem.dart';
import 'package:flutter_wallet/setting/YSShare.dart';
import 'package:flutter_wallet/tools/YSColors.dart';
import 'package:flutter_wallet/wallet/YSWalletManager.dart';

import '../login/view/YSHelpView.dart';
import '../tools/YSTools.dart';

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

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

class YSSettingState extends State<YSSetting> {
  @override
  Widget build(BuildContext context) {
    List _menuArray = [
      {'image':'形状 3','title':S.current.GUANLIQIANBAO,'type':1},
      {'image':'地址 (2)','title':S.current.CHANGYONGDIZHI,'type':2},
      {'image':'moon-b-月亮备份','title':S.current.HEIANMOSHI,'type':3},
      {'image':'分享 (2)','title':S.current.FENXIANGYINGYONG,'type':4},
      // {'image':'说明 (1)','title':S.current.QIANBAOSHUOMING,'type':5},
      {'image':'关于我们 (2)','title':S.current.GUANYUMOMEN,'type':6},
      {'image':'形状结合 5','title':S.current.XITONGSHEZHI,'type':7}
    ];
    return Scaffold(
      body: SingleChildScrollView(
        child: SizedBox(
          width: ysWidth(context),
          child: Stack(
            children: [
              const YSHeadView(),
              Padding(
                padding: EdgeInsets.only(top: ysTOP(context)+hsp(10)),
                child: Column(
                  children: [
                    Container(
                      height: hsp(50),
                      padding: EdgeInsets.only(left: hsp(20),right: hsp(20)),
                      child: Row(
                        mainAxisAlignment: MainAxisAlignment.spaceBetween,
                        children: [
                          Text(S.of(context).SHEZHI,style: YSColors.title2Style(context),),
                          const YSCapsule()
                        ],
                      ),
                    ),
                    Container(
                      margin: EdgeInsets.only(top: hsp(15)),
                      height: ysHeight(context)-ysTOP(context)-147,
                      decoration: BoxDecoration(
                        color: YSColors.containColor(context),
                        borderRadius: const BorderRadius.only(topLeft: Radius.circular(10),topRight: Radius.circular(10)),
                        boxShadow: [
                          BoxShadow(color: YSColors.shadowColor(context),blurRadius: 5)
                        ]
                      ),
                      child: ListView.builder(
                        itemBuilder: (context,index){
                          Map item = _menuArray[index];
                          return GestureDetector(
                            onTap: (){
                              int type = item['type'];
                              switch(type){
                                case 1:{
                                  Navigator.of(context).push(
                                      CupertinoPageRoute(builder: (context){
                                        return const YSWalletManager2();
                                      })
                                  );
                                }break;
                                case 2:{
                                  Navigator.of(context).push(
                                      CupertinoPageRoute(builder: (context){
                                        return const YSAlwayAddress();
                                      })
                                  );
                                }break;
                                case 4:{
                                  Navigator.of(context).push(
                                      CupertinoPageRoute(builder: (context){
                                        return const YSShare();
                                      })
                                  );
                                }break;
                                case 5:{

                                }break;
                                case 6:{
                                  Navigator.of(context).push(
                                      CupertinoPageRoute(builder: (context){
                                        return const YSAboutUs();
                                      })
                                  );
                                }break;
                                case 7:{
                                  Navigator.of(context).push(
                                    CupertinoPageRoute(builder: (context){
                                      return const YSSettingSystem();
                                    })
                                  ).then((value) {
                                    setState(() {});
                                  });
                                }break;
                              }
                            },
                            behavior: HitTestBehavior.opaque,
                            child: Container(
                              decoration: BoxDecoration(
                                border: Border(bottom: BorderSide(color: YSColors.lineColor(context),width: 0.5))
                              ),
                              height: hsp(50)-0.5,
                              child: Row(
                                children: [
                                  Image.asset(YSColors.imageStyle(context, item['image']),height: hsp(10),width: hsp(10),),
                                  Expanded(
                                    child: Padding(
                                      padding: EdgeInsets.only(left: hsp(10),right: hsp(10)),
                                      child: Text(item['title'],style: YSColors.contentStyle(context),)
                                    )
                                  ),
                                  if(item['title']==S.current.HEIANMOSHI)YSSWitchView(valueSetter: (value){
                                    setThemFunc(context, value?darkTheme:lightTheme);
                                    String valueStr = value?'dart':'light';
                                    YSSharedPreferences.setStringValue('them',valueStr);
                                    YSUserRecord().them = valueStr;
                                  },type: 1,)
                                ],
                              ),
                            ),
                          );
                        },
                        itemCount: _menuArray.length,
                        padding: EdgeInsets.only(left: hsp(15),right: hsp(15)),
                        shrinkWrap: true,
                        physics: const NeverScrollableScrollPhysics(),
                      ),
                    )
                  ],
                ),
              )
            ],
          ),
        ),
      ),
    );
  }
}
