import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'package:huixiang/generated/l10n.dart';
import 'package:huixiang/utils/font_weight.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:pin_input_text_field/pin_input_text_field.dart';

class PlatformPayCode extends StatefulWidget {
  final Map<String, dynamic> arguments;
  PlatformPayCode({this.arguments});

  @override
  State<StatefulWidget> createState() {
    return _PlatformPayCode();
  }
}

class _PlatformPayCode extends State<PlatformPayCode> {
  String inputCode = "";

  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
        behavior: HitTestBehavior.translucent,
        onTap: () {
          FocusScope.of(context).requestFocus(FocusNode());
        },
        child: Scaffold(
          appBar: AppBar(
            backgroundColor: Colors.white,
            leading: GestureDetector(
                child: Icon(
                  Icons.arrow_back_ios,
                  color: Colors.black,
                ),
                onTap: () {
                  Navigator.of(context).pop();
                }),
            title: Text(
              S.of(context).pingtaizhifumima,
              style: TextStyle(
                fontWeight: MyFontWeight.regular,
                fontSize: 17.sp,
                color: Color(0xFF0D0D0D),
              ),
            ),
            centerTitle: true,
            elevation: 0.0,
          ),
          body: Column(
            children: [
              settingCode(),
            ],
          ),
        ));
  }

  ///设置密码
  Widget settingCode(){
    return Container(
      alignment: Alignment.center,
      margin: EdgeInsets.only(top: 28.h),
      child: Column(
        mainAxisAlignment: MainAxisAlignment.start,
        crossAxisAlignment: CrossAxisAlignment.center,
        children: [
          Text(
            "请输入6位数字密码",
            style: TextStyle(
              fontWeight: MyFontWeight.semi_bold,
              fontSize: 18.sp,
              color: Color(0xFF353535),
            ),
          ),
          SizedBox(
            height: 12.h,
          ),
          Text(
            "将用于海峡姐妹APP下单时平台余额消费",
            style: TextStyle(
              fontWeight: MyFontWeight.medium,
              fontSize: 14.sp,
              color: Color(0xFFA29E9E),
            ),
          ),
          Container(
            margin: EdgeInsets.only(top: 24.h, bottom: 31.h,right: 35.w,left: 35.w),
            height: 45.h,
            child: PinInputTextField(
              onChanged: (txtCode){
                print(txtCode);
                setState(() {
                  inputCode = txtCode;
                });
              },
              decoration: BoxLooseDecoration(
                  strokeColorBuilder: FixedColorBuilder(Color(0xFFEBEAEA)),
                  textStyle: TextStyle(
                    fontWeight: MyFontWeight.medium,
                    fontSize: 18.sp,
                    color: Color(0xFF353535),
                  ),
                  radius: Radius.circular(4.r)),
            ),
          ),
          GestureDetector(
            onTap: (){
              setState(() {
                if(inputCode.length == 6){
                  Navigator.of(context).pushReplacementNamed('/router/platform_pay_code_success',arguments:{
                    "inputCode":inputCode,
                    "inputText":widget.arguments["inputText"]
                  });
                }else{
                  SmartDialog.showToast("请输入6位数字密码", alignment: Alignment.center);
                }
              });
            },
            child: Container(
              width: 163.w,
              height: 46.h,
              alignment: Alignment.center,
              decoration: BoxDecoration(
                color: inputCode.length == 6 ? Color(0xFF32A060):Color(0xFFBBE7CC),
                borderRadius: BorderRadius.circular(23.r),
              ),
              child: Text(
                "下一步",
                style: TextStyle(
                  fontWeight: MyFontWeight.semi_bold,
                  fontSize: 18.sp,
                  color: Color(0xFFFFFFFF),
                ),
              ),
            ),
          )
        ],
      ),
    );
  }

}