import 'package:cpt_auth/modules/sign_up/sign_up_controller.dart';
import 'package:cpt_auth/modules/sign_up/sign_up_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 SignUpPage extends BaseStatefulPage<SignUpController> {
  SignUpPage({Key? key}) : super(key: key);

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

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

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

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

class _SignUpState extends BaseState<SignUpPage, SignUpController> {
  late SignUpState 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, "Sign up".tr),
        body: SafeArea(
        bottom: MediaQuery.of(context).padding.bottom > 38,
          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: "Email".tr).marginOnly(left: 15, top: 19),

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

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

                  CustomTextField(
                    formKey: "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.doSignUp();
                    },
                    marginTop: 10,
                  ),

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