import 'package:flutter/cupertino.dart';
import 'package:flutter_wallet/base/YSBase.dart';
import 'package:flutter_wallet/generated/l10n.dart';
import 'package:flutter_wallet/login/YSWalletKnow.dart';
import 'package:flutter_wallet/login/view/YSHelpView.dart';
import 'package:flutter_wallet/tools/YSColors.dart';
import 'package:flutter_wallet/tools/YSNetWork.dart';
import 'package:flutter_wallet/tools/YSTools.dart';

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

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

class YSWalletCreateState extends State<YSWalletCreate> {
  String _name = '';
  String _pass = '';
  String _word = '';
  bool _isFing = true;
  bool _isAgree = false;
  bool _isSec = true;
  @override
  Widget build(BuildContext context) {
    return YSBase2(
      isScroll: false,
      titleType: 1,
      ysChild: Padding(
        padding: EdgeInsets.only(top: hsp(20)),
        child: Column(
          children: [
            Image.asset('images/沙漏黑白.gif',height: hsp(80),width: hsp(80),),
            const YSIndexView(selectedIndex: 0,),
            Expanded(
              child: Padding(
                padding: EdgeInsets.only(top: hsp(20)),
                child: ClipRRect(
                  borderRadius: const BorderRadius.only(topLeft: Radius.circular(10),topRight: Radius.circular(10)),
                  child: Container(
                    width: ysWidth(context),
                    padding: EdgeInsets.only(top: hsp(15),bottom: hsp(15),left: 15,right: 15),
                    color: YSColors.backgroundColor(context),
                    child: Column(
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: [
                        Container(
                          margin: EdgeInsets.only(bottom: hsp(10)),
                          alignment: Alignment.center,
                          child: Text(S.current.CHUANGJIANQIANBAO2,style: YSColors.titleStyle(context),),
                        ),
                        Text(S.current.SHEZHIQIANBAOMINGCHENG,style: YSColors.contentStyle(context),),
                        YSInputView(tips: S.current.QIANBAOMINGCHENG,valueSetter: (value){
                          _name = value;
                        },),
                        Padding(
                          padding: EdgeInsets.only(top: hsp(15),bottom: hsp(5)),
                          child: Row(
                            children: [
                              Expanded(child: Text(S.current.SHEZHIQIANBAOMIMA,style: YSColors.contentStyle(context),),),
                              GestureDetector(
                                onTap: (){
                                  _isSec = !_isSec;
                                  setState(() {});
                                },
                                child: Image.asset(YSColors.imageStyle(context, _isSec?'yanjing_yincang':'眼睛'),height: hsp(20),width: hsp(20),color: YSColors.alertColor(context),),
                              )
                            ],
                          )
                        ),
                        Text('※${S.current.BAKEWALLETBUHUICUNCHUNINDEMIMA}',style: YSColors.subStyle(context),),
                        YSInputView(tips: S.current.ZHISHAOBAWEISHUZIJIDAXIAOXIEZIMU,valueSetter: (value){
                          _pass = value;
                        },isSec: _isSec),
                        YSInputView(tips: S.current.CHONGFUSHURUYISHANGMIMA,valueSetter: (value){
                          _word = value;
                        },isSec: _isSec,),
                        Padding(
                          padding: EdgeInsets.only(top: hsp(10)),
                          child: Row(
                            mainAxisAlignment: MainAxisAlignment.spaceBetween,
                            children: [
                              Expanded(child: Text(S.current.SHIYONGFACEIDZHIWENDENGLU,style: YSColors.contentStyle(context),),),
                              YSSWitchView(valueSetter: (value){
                                _isFing = value;
                              })
                            ],
                          ),
                        ),
                        Padding(
                          padding: EdgeInsets.only(top: hsp(10)),
                          child: Row(
                            mainAxisAlignment: MainAxisAlignment.spaceBetween,
                            children: [
                              YSCheckView(valueSetter: (value){
                                _isAgree = value;
                              }),
                              Expanded(child: Text(' ${S.current.WOLIAOJIEBAKEWALLETWUFAWEIWOZHAOHUIMIMA}',style: YSColors.subStyle(context),),),

                            ],
                          ),
                        )
                      ],
                    ),
                  )
                ),
              )
            ),
            Container(
              padding: EdgeInsets.only(top: hsp(20),bottom: hsp(20),left: hsp(20),right: hsp(20)),
              color: YSColors.backgroundColor(context),
              child: GestureDetector(
                onTap: (){
                  _postWalletData();
                },
                child: Container(
                  height: hsp(50),
                  decoration: BoxDecoration(
                    color: YSColors.buttonColor(context),
                    borderRadius: const BorderRadius.all(Radius.circular(10)),
                  ),
                  alignment: Alignment.center,
                  child: Text(S.current.CHUANGJIANQIANBAO,style: YSColors.buttonStyle(context),),
                ),
              ),
            )
          ],
        ),
      ),
    );
  }

  _postWalletData() async{
    if(_name.isEmpty){
      ysFlutterToast(S.current.QIANBAOMINGCHENGBUNENGWEIKONG);
      return;
    }
    bool isPass = isPassword(_pass);
    if(!isPass){
      ysFlutterToast(S.current.ZHISHAOBAWEISHUZIJIDAXIAOXIEZIMU);
      return;
    }
    if(_word.isEmpty){
      ysFlutterToast(S.current.CHONGFUSHURUYISHANGMIMA);
      return;
    }
    if(_word!=_pass){
      ysFlutterToast(S.current.LIANGCIMIMASHURUBUYIZHI);
      return;
    }
    if(!_isAgree){
      ysFlutterToast(S.current.DIANJIXUANZHONGLIAOJIEMIMAZHAOHUI);
      return;
    }
    YSData().name = _name;
    YSData().password = _pass;
    Navigator.of(context).push(
        CupertinoPageRoute(builder: (context){
          return const YSWalletKnow();
        })
    );
  }
}
