import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_wallet/base/YSBase.dart';
import 'package:flutter_wallet/generated/l10n.dart';
import 'package:flutter_wallet/login/view/YSHelpView.dart';
import 'package:flutter_wallet/setting/YSAgreement.dart';
import 'package:flutter_wallet/setting/YSSettingLanguage.dart';
import 'package:flutter_wallet/setting/YSSettingThem.dart';
import 'package:flutter_wallet/setting/YSSettingUnit.dart';
import 'package:flutter_wallet/tools/YSAlertView.dart';
import 'package:flutter_wallet/tools/YSColors.dart';
import 'package:flutter_wallet/tools/YSNetWork.dart';
import 'package:flutter_wallet/tools/YSSqflite.dart';
import 'package:flutter_wallet/tools/YSTools.dart';

import '../wallet/YSWalletRocChoose.dart';
import 'YSSettingPrice.dart';

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

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

class YSSettingSystemState extends State<YSSettingSystem> {
  @override
  Widget build(BuildContext context) {
  List _menuArray = [
  {'title':S.current.YUYAN,'type':1,'value':'','key':1},
  {'title':S.current.JIEDIANSHEZHI,'type':1,'value':'','key':2},
  {'title':S.current.ZHUTIMOSHI,'type':1,'value':'','key':3},
  {'title':S.current.HUOBIDANWEI,'type':1,'value':'','key':4},
  {'title':S.current.HANGQINGSHEZHI,'type':3,'value':'','key':5},
  {'title':S.current.ZHANGDIEFUJIZHUN,'type':1,'value':'','key':6},
  {'title':S.current.YINGYONGSUO,'type':2,'value':'','key':7},
  // {'title':S.current.YIJIANQIANYI,'type':1,'value':'','key':8},
  // {'title':S.current.DAPPBAIMINGDAN,'type':1,'value':'','key':9},
  // {'title':S.current.KAIQINOSTR,'type':2,'value':'','key':10},
  // {'title':S.current.KAIFAZHEMOSHI,'type':2,'value':'','key':11},
  // {'title':S.current.WANGLUOJIANCE,'type':1,'value':'','key':12},
    {'title':S.current.QINGCHUHUANCUN,'type':1,'value':'','key':13},
    // {'title':'日志信息','type':1,'value':'','key':14}
  ];
    return YSBase(
      ysTitle: S.current.XITONGSHEZHI2,
      ysChild: ListView.separated(
        itemBuilder: (context,index){
          Map item = _menuArray[index];
          return GestureDetector(
            onTap: () {
              int key = item['key'];
              switch(key){
                case 1:{
                  Navigator.of(context).push(
                    CupertinoPageRoute(builder: (context){
                      return const YSSettingLanguage();
                    })
                  ).then((value) {
                    setState(() {});
                  });
                }
                break;
                case 2:{
                  Navigator.of(context).push(
                    CupertinoPageRoute(builder: (context){
                      return const YSWalletRocChoose();
                    })
                  );
                }
                break;
                case 3:{
                  Navigator.of(context).push(
                      CupertinoPageRoute(builder: (context){
                        return const YSSettingThem();
                      })
                  );
                }
                break;
                case 4:{
                  Navigator.of(context).push(
                      CupertinoPageRoute(builder: (context){
                        return const YSSettingUnit();
                      })
                  );
                }
                break;
                case 5:{
                  Navigator.of(context).push(
                      CupertinoPageRoute(builder: (context){
                        return const YSSettingPrice();
                      })
                  );
                }
                break;
                case 6:{}
                break;
                case 7:{}
                break;
                case 8:{}
                break;
                case 9:{}
                break;
                case 10:{}
                break;
                case 11:{}
                break;
                case 12:{}
                break;
                case 13:{
                  ysShowCenterAlertView(context, YSTipsAlertView(valueSetter: (value) async{
                    if(value){
                      int status = await YSSqflite3().delete();
                      LogUtil.d(status);
                      ysFlutterToast(S.current.HAUNCUNYIQINGCHU);
                    }
                  },tipsStr: '${S.current.QINGCHUHUANCUN}?',));
                }
                break;
                case 14:{
                  Navigator.of(context).push(
                      CupertinoPageRoute(builder: (context){
                        return const YSAgreement(type: 3);
                      })
                  );
                }
                break;
              }
            },
            behavior: HitTestBehavior.opaque,
            child: Container(
              height: hsp(45),
              color: YSColors.containColor(context),
              padding: EdgeInsets.only(left: hsp(15),right: hsp(15)),
              child: Row(
                children: [
                  Expanded(
                    child: Text(item['title'],style: YSColors.contentStyle(context),)
                  ),
                  Expanded(
                    child: Text(item['value'],style: YSColors.contentStyle(context),)
                  ),
                  item['type']==2?YSSWitchView(
                    valueSetter: (value){
                      YSSharedPreferences.setStringValue('lock', value?'1':'0');
                    },
                    type: 3,
                  ):Icon(Icons.chevron_right,size: hsp(20),color: YSColors.shadowColor(context),)
                ],
              ),
            ),
          );
        },
        separatorBuilder: (context,index){
          return Container(height: hsp(index==2||index==5||index==6||index==7?20:0),);
        },
        itemCount: _menuArray.length,
        padding: const EdgeInsets.all(0),
        shrinkWrap: true,
        physics: const NeverScrollableScrollPhysics(),
      ),
    );
  }
}
