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

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

import '../../../base/base_view.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(
                'Sign up to NOMO',
                style: TextStyle(
                  fontSize: 28.sp,
                  height: 1.2,
                  color: Get.reactiveTheme.textTheme.bodyLarge!.color,
                ),
              ),

              24.verticalSpaceFromWidth,

              // 描述文字
              Text(
                'After registration, your free trial will be deducted, and other membership time shifts to your account for multi-device use.',
                style: TextStyle(
                  fontSize: 16.sp,
                  color: Get.reactiveTheme.hintColor,
                  height: 1.4,
                ),
              ),

              20.verticalSpaceFromWidth,
              IXTextField(
                hintText: 'Username',
                prefixIcon: Icons.person_outline,
                controller: controller.usernameController,
                focusNode: controller.usernameFocusNode,
                validator: controller.validatorInputValue,
                tipText: '6-20 characters (letters or numbers)',
                errorText: '6-20 characters (letters or numbers)',
                onChanged: (value) {
                  controller.checkSignup();
                },
              ),

              16.verticalSpaceFromWidth,
              IXTextField(
                hintText: 'Password',
                prefixIcon: Icons.lock_outline,
                controller: controller.passwordController,
                focusNode: controller.passwordFocusNode,
                validator: controller.validatorInputValue,
                isPassword: true,
                tipText: '6-20 characters (letters or numbers)',
                errorText: '6-20 characters (letters or numbers)',
                onChanged: (value) {
                  controller.checkSignup();
                },
              ),
              156.verticalSpaceFromWidth,
              SubmitButton(
                text: 'Sign Up',
                enabled: controller.isSignup,
                onPressed: () {},
              ),
              10.verticalSpaceFromWidth,
              // 底部注册链接
              Center(
                child: RichText(
                  text: TextSpan(
                    children: [
                      TextSpan(
                        text: 'Already have an account? ',
                        style: TextStyle(
                          color: Colors.grey[500],
                          fontSize: 14.sp,
                        ),
                      ),
                      TextSpan(
                        text: ' Login now',
                        recognizer: TapGestureRecognizer()
                          ..onTap = () {
                            Get.toNamed(Routes.LOGIN);
                          },
                        style: TextStyle(
                          color: Get.reactiveTheme.primaryColor,
                          fontSize: 14.sp,
                          fontWeight: FontWeight.w400,
                        ),
                      ),
                    ],
                  ),
                ),
              ),
            ],
          ),
        ),
      ),
    );
  }
}
