import 'package:cpt_auth/modules/reset_psd/reset_psd_controller.dart';
import 'package:cpt_auth/modules/reset_psd/reset_psd_state.dart';
import 'package:cs_resources/constants/color_constants.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:plugin_basic/base/base_state.dart';
import 'package:plugin_basic/base/base_stateful_page.dart';
import 'package:plugin_basic/utils/ext_get_nav.dart';
import 'package:router/path/router_path.dart';
import 'package:shared/utils/screen_util.dart';
import 'package:widgets/ext/ex_widget.dart';
import 'package:widgets/my_appbar.dart';
import 'package:widgets/my_button.dart';
import 'package:widgets/shatter/form_require_text.dart';
import 'package:widgets/shatter/round_my_text_field.dart';

class ResetPasswordPage extends BaseStatefulPage<ResetPasswordController> {
  ResetPasswordPage({Key? key}) : super(key: key);

  //启动当前页面
  static void startInstance() {
    return Get.start(RouterPath.authResetPassword);
  }

  @override
  Widget build(BuildContext context) {
    return Container();
  }

  @override
  ResetPasswordController createRawController() {
    return ResetPasswordController();
  }

  @override
  State<ResetPasswordPage> createState() => _SignUpState();
}

class _SignUpState extends BaseState<ResetPasswordPage, ResetPasswordController> {
  late ResetPasswordState state;

  @override
  void initState() {
    super.initState();
    state = controller.state;
  }

  @override
  Widget build(BuildContext context) {
    return autoCtlGetBuilder(builder: (controller) {
      return Scaffold(
        extendBodyBehindAppBar: true,
        appBar: MyAppBar.appBar(context, "Reset Password".tr),
        body: SafeArea(
          bottom: true,
          top: false,
          child: Container(
            width: double.infinity,
            height: double.infinity,
            padding: EdgeInsets.only(top: kToolbarHeight + ScreenUtil.getStatusBarH(context) + 1),
            decoration: const BoxDecoration(
              gradient: LinearGradient(
                colors: [
                  Color(0xFF091D44),
                  Color(0xFF245A8A),
                  Color(0xFF7F7CEC),
                ],
                begin: Alignment.topCenter,
                end: Alignment.bottomCenter,
              ),
            ),
            child: SingleChildScrollView(
              scrollDirection: Axis.vertical,
              physics: const BouncingScrollPhysics(),
              child: Column(
                mainAxisSize: MainAxisSize.max,
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  //旧密码的设置
                  FormRequireText(text: "Old Password".tr).marginOnly(left: 15, top: 19),

                  CustomTextField(
                    formKey: "old_password",
                    formData: state.formData,
                    errorText: state.passwordErrorText,
                    onSubmit: (key, value) {
                      state.formData[key]!['focusNode'].unfocus();
                      FocusScope.of(context).requestFocus(state.formData['new_password']!['focusNode']);
                    },
                    marginTop: 10,
                  ),

                  //新密码的设置
                  FormRequireText(text: "New Password".tr).marginOnly(left: 15, top: 19),

                  CustomTextField(
                    formKey: "new_password",
                    formData: state.formData,
                    errorText: state.passwordErrorText,
                    onSubmit: (key, value) {
                      state.formData[key]!['focusNode'].unfocus();
                      FocusScope.of(context).requestFocus(state.formData['confirm_password']!['focusNode']);
                    },
                    marginTop: 10,
                  ),

                  //确认密码的设置
                  FormRequireText(text: "Confirm Password".tr).marginOnly(left: 15, top: 19),

                  CustomTextField(
                    formKey: "confirm_password",
                    formData: state.formData,
                    errorText: state.confirmPasswordErrorText,
                    textInputAction: TextInputAction.done,
                    onSubmit: (key, value) {
                      FocusScope.of(context).unfocus();
                      controller.doResetPassword();
                    },
                    marginTop: 10,
                  ),

                  //提交按钮
                  MyButton(
                    type: ClickType.throttle,
                    milliseconds: 500,
                    onPressed: () {
                      FocusScope.of(context).unfocus();
                      controller.doResetPassword();
                    },
                    text: "Submit".tr,
                    textColor: ColorConstants.white,
                    fontSize: 16,
                    radius: 22.5,
                    backgroundColor: hexToColor("#FFBB1B"),
                    fontWeight: FontWeight.w500,
                  ).marginSymmetric(horizontal: 15, vertical: 25),
                ],
              ),
            ),
          ),
        ),
      );
    });
  }
}
