import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

import 'package:get/get.dart';
import 'package:flashlink/config/theme/theme_extensions/theme_extension.dart';

import '../../../../config/translations/strings_enum.dart';
import '../../../base/base_view.dart';
import '../../../constants/iconfont/iconfont.dart';
import '../../../routes/app_pages.dart';
import '../../../widgets/ix_app_bar.dart';
import '../../../widgets/ix_text_field.dart';
import '../../../widgets/submit_btn.dart';
import '../controllers/signup_controller.dart';

class SignupView extends BaseView<SignupController> {
  const SignupView({super.key});

  @override
  PreferredSizeWidget? get appBar => IXAppBar(title: '');

  @override
  Widget buildContent(BuildContext context) {
    return SafeArea(
      child: Padding(
        padding: EdgeInsets.symmetric(horizontal: 14.w),
        child: SingleChildScrollView(
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              10.verticalSpaceFromWidth,

              // 标题
              Text(
                Strings.signup.tr,
                style: TextStyle(
                  fontSize: 28.sp,
                  height: 1.2,
                  color: Get.reactiveTheme.textTheme.bodyLarge!.color,
                ),
              ),

              24.verticalSpaceFromWidth,

              // 描述文字
              Text(
                Strings.signupDescription.tr,
                style: TextStyle(
                  fontSize: 16.sp,
                  color: Get.reactiveTheme.hintColor,
                  height: 1.4,
                ),
              ),

              20.verticalSpaceFromWidth,
              IXTextField(
                hintText: Strings.username.tr,
                prefixIcon: IconFont.icon10,
                controller: controller.usernameController,
                focusNode: controller.usernameFocusNode,
                validator: controller.validatorInputValue,
                tipText: Strings.usernamePasswordRule.tr,
                errorText: Strings.usernamePasswordRule.tr,
                onChanged: (value) {
                  controller.checkSignup();
                },
              ),

              16.verticalSpaceFromWidth,
              IXTextField(
                hintText: Strings.password.tr,
                prefixIcon: IconFont.icon11,
                controller: controller.passwordController,
                focusNode: controller.passwordFocusNode,
                validator: controller.validatorInputValue,
                isPassword: true,
                tipText: Strings.usernamePasswordRule.tr,
                errorText: Strings.usernamePasswordRule.tr,
                onChanged: (value) {
                  controller.checkSignup();
                },
              ),
              156.verticalSpaceFromWidth,
              SubmitButton(
                text: Strings.signupButton.tr,
                enabled: controller.isSignup,
                onPressed: controller.handleSignUp,
              ),
              20.verticalSpaceFromWidth,
              // 底部注册链接
              Center(
                child: RichText(
                  text: TextSpan(
                    children: [
                      TextSpan(
                        text: Strings.alreadyHaveAccount.tr,
                        style: TextStyle(
                          color: Colors.grey[500],
                          fontSize: 14.sp,
                        ),
                      ),
                      TextSpan(
                        text: Strings.loginNow.tr,
                        recognizer: TapGestureRecognizer()
                          ..onTap = () {
                            Get.toNamed(Routes.LOGIN);
                          },
                        style: TextStyle(
                          color: Get.reactiveTheme.primaryColor,
                          fontSize: 14.sp,
                          fontWeight: FontWeight.w400,
                        ),
                      ),
                    ],
                  ),
                ),
              ),
            ],
          ),
        ),
      ),
    );
  }
}
