import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_wallet/login/view/YSHelpView.dart';
import 'package:flutter_wallet/tools/YSAlertView.dart';
import 'package:flutter_wallet/tools/YSBip.dart';
import '../base/YSBase.dart';
import '../generated/l10n.dart';
import '../tools/YSColors.dart';
import '../tools/YSTools.dart';
import 'YSWalletWordCheck.dart';

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

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

class YSWalletWordState extends State<YSWalletWord> {
  final List _tipsArray = [
    {'tips':S.current.QINGSHOUDONGZAIYIZHANGZHISHANG},
    {'tips':S.current.QINGWUJIANGZHUJICITOULOU},
    {'tips':S.current.QINGWUTONGGUOJIEPING},
    {'tips':S.current.QINGWUQINGYIXIEZAI},
    {'tips':S.current.JIANYIDUOGEDIFANG}
  ];
  List _wordsArray = [];
  @override
  void initState() {
    _getWords();
    super.initState();
  }
  _getWords() async{
    String wordStr = YSBipManager.getMnemonic();
    _wordsArray = wordStr.split(' ');
    setState(() {});
  }
  @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: 1,),
            Expanded(
                child: Padding(
                  padding: EdgeInsets.only(top: hsp(20),left: hsp(20),right: 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(20),bottom: hsp(15),left: 15,right: 15),
                        color: YSColors.containColor(context),
                        child: SingleChildScrollView(
                          child: Column(
                            crossAxisAlignment: CrossAxisAlignment.start,
                            children: [
                              Container(
                                alignment: Alignment.center,
                                child: Text(S.current.BEIFENZHUJICI2,style: YSColors.titleStyle(context),),
                              ),
                              Container(
                                margin: EdgeInsets.only(top: hsp(15)),
                                decoration: BoxDecoration(
                                  color: YSColors.contain2Color(context)
                                ),
                                child: _wordsArray.isEmpty?Container():GridView.builder(
                                  gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
                                    crossAxisCount: 3,
                                    childAspectRatio: 71/22,
                                    mainAxisSpacing: hsp(10),
                                    crossAxisSpacing: hsp(10)
                                  ),
                                  itemBuilder: (context,index){
                                    String word = _wordsArray[index];
                                    return Container(
                                      decoration: const BoxDecoration(
                                        color: Colors.white,
                                        borderRadius: BorderRadius.all(Radius.circular(5))
                                      ),
                                      alignment: Alignment.center,
                                      child: Text(word,style: YSColors.sub3Style(context),),
                                    );
                                  },
                                  padding: EdgeInsets.all(hsp(15)),
                                  itemCount: _wordsArray.length,
                                  shrinkWrap: true,
                                  physics: const NeverScrollableScrollPhysics(),
                                ),
                              ),

                              Padding(
                                padding: EdgeInsets.only(top: hsp(25)),
                                child: Row(
                                  children: [
                                    Image.asset(YSColors.imageStyle(context, '截屏2023'),height: hsp(12),width: hsp(15),),
                                    Text(' ${S.current.ZHONGYAOTISHI}：',style: TextStyle(fontSize: zsp(12),color: const Color(0xFFED260C)),)
                                  ],
                                )
                              ),
                              ListView.separated(
                                itemBuilder: (context,index){
                                  Map item = _tipsArray[index];
                                  return Text(item['tips'],style: TextStyle(fontSize: zsp(10),color: const Color(0xFFED260C)),);
                                },
                                separatorBuilder: (context,index){
                                  return Container(height: hsp(15),);
                                },
                                itemCount: _tipsArray.length,
                                shrinkWrap: true,
                                physics: const NeverScrollableScrollPhysics(),
                                padding: EdgeInsets.only(top: hsp(10)),
                              )
                            ],
                          ),
                        ),
                      )
                  ),
                )
            ),
            Padding(
              padding: EdgeInsets.only(left: hsp(20),right: hsp(20)),
              child: Container(
                padding: EdgeInsets.only(top: hsp(20),bottom: hsp(20),left: hsp(20),right: hsp(20)),
                color: YSColors.containColor(context),
                child: GestureDetector(
                  onTap: (){
                    ysShowCenterAlertView(context, YSTipsAlertView(valueSetter: (value){
                      if(value){
                        Navigator.of(context).push(
                            CupertinoPageRoute(builder: (context){
                              return YSWalletWordCheck(wordsArray: _wordsArray,);
                            })
                        );
                      }
                    },tipsStr: S.current.QINGQUERENNIYIJINGBEIFENLEZHUJICI,));

                  },
                  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.BEIFENWANCHENG,style: YSColors.buttonStyle(context),),
                  ),
                ),
              ),
            )
          ],
        ),
      ),
    );
  }
}
