import 'package:food_delivery_client/core/helpers/validator_helpers.dart';
import 'package:food_delivery_client/feature/auth/presentation/widgets/w_auth_background.dart';
import '../../../../../../food_delivery_client.dart';

class WRegisterBody extends StatefulWidget {
  const WRegisterBody({super.key});

  @override
  State<WRegisterBody> createState() => _WRegisterBodyState();
}

class _WRegisterBodyState extends State<WRegisterBody> {
  late TextEditingController _firstNameController;
  late TextEditingController _lastNameController;
  late TextEditingController _phoneNumberController;
  late TextEditingController _passwordController;
  late TextEditingController _repeatPasswordController;

  final _formKey = GlobalKey<FormState>();

  @override
  void initState() {
    _firstNameController = TextEditingController();
    _lastNameController = TextEditingController();
    _phoneNumberController = TextEditingController();
    _passwordController = TextEditingController();
    _repeatPasswordController = TextEditingController();
    super.initState();
  }

  @override
  void dispose() {
    _firstNameController.dispose();
    _lastNameController.dispose();
    _phoneNumberController.dispose();
    _passwordController.dispose();
    _repeatPasswordController.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Form(
      key: _formKey,
      child: WAuthBackground(
        child: SizedBox(
          width: context.w,
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              20.verticalSpace,
              Align(
                alignment: AlignmentGeometry.center,
                child: Text(
                  context.loc.sign_up,
                  style: AppTextStyles.size24Bold,
                ),
              ),
              20.verticalSpace,
              Text(
                context.loc.first_name,
                style: AppTextStyles.size14Regular.copyWith(
                  color: AppColors.c6A6E7F,
                ),
              ),
              5.verticalSpace,
              AppTextFormField(
                hintText: context.loc.enter_first_name,
                controller: _firstNameController,
                borderRadius: AppUtils.kBorderRadius8,
                keyBoardType: TextInputType.name,
                validator: (value) {
                  return Validators.validateFields(
                    _firstNameController.text.trim(),
                  );
                },
              ),
              10.verticalSpace,
              Text(
                'Last name',
                style: AppTextStyles.size14Regular.copyWith(
                  color: AppColors.c6A6E7F,
                ),
              ),
              5.verticalSpace,
              AppTextFormField(
                hintText: "Enter LastName",
                controller: _lastNameController,
                borderRadius: AppUtils.kBorderRadius8,
                keyBoardType: TextInputType.text,
                validator: (value) {
                  return Validators.validateFields(
                    _lastNameController.text.trim(),
                  );
                },
              ),
              10.verticalSpace,
              /* Text(
                context.loc.phone_number,
                style: AppTextStyles.size14Regular.copyWith(
                  color: AppColors.c6A6E7F,
                ),
              ),
              5.verticalSpace,
              AppTextFormField(
                hintText: context.loc.enter_phone_number,
                controller: _phoneNumberController,
                borderRadius: AppUtils.kBorderRadius8,
                keyBoardType: TextInputType.phone,
                prefixIcon: Text("+ 998", style: AppTextStyles.size16Regular),
                inputFormatters: [
                  FilteringTextInputFormatter.digitsOnly,
                  Formatters.phoneFormatter,
                  LengthLimitingTextInputFormatter(12),
                ],
                validator: (value) {
                  return Validators.validatePhoneNumber(
                    _phoneNumberController.text.trim(),
                  );
                },
              ),

               */
              10.verticalSpace,
              Text(
                context.loc.enter_password,
                style: AppTextStyles.size14Regular.copyWith(
                  color: AppColors.c6A6E7F,
                ),
              ),
              5.verticalSpace,
              AppTextFormField(
                obscureText: true,
                hintText: context.loc.password,
                controller: _passwordController,
                borderRadius: AppUtils.kBorderRadius8,
                keyBoardType: TextInputType.visiblePassword,
                validator: (value) {
                  return Validators.validatePassword(
                    _passwordController.text.trim(),
                  );
                },
              ),
              10.verticalSpace,

              Text(
                context.loc.repeat_password,
                style: AppTextStyles.size14Regular.copyWith(
                  color: AppColors.c6A6E7F,
                ),
              ),
              5.verticalSpace,
              AppTextFormField(
                obscureText: true,
                hintText: context.loc.enter_repeat_password,
                controller: _repeatPasswordController,
                borderRadius: AppUtils.kBorderRadius8,
                keyBoardType: TextInputType.visiblePassword,
                validator: (value) {
                  return Validators.validatePassword(
                    _repeatPasswordController.text.trim(),
                  );
                },
              ),
              20.verticalSpace,
              AppButton(
                name: context.loc.continue_str,
                borderRadius: 15,

                backgroundColor: AppColors.c34A853,
                trailing: SvgPicture.asset(
                  AppIcons.icArrowRightLight,
                ).paddingOnly(left: 8),
                onPressed: () {
                  if (_formKey.currentState?.validate() ?? false) {


                  }
                },
              ),
              20.verticalSpace,
              Row(
                mainAxisAlignment: MainAxisAlignment.center,
                children: [
                  Text(
                    context.loc.already_has_account,
                    style: AppTextStyles.size14Medium,
                  ),
                  TextButton(
                    onPressed: () {
                      context.pushReplacement(Routes.login);
                    },
                    child: Text(
                      context.loc.login,
                      style: AppTextStyles.size15Bold.copyWith(
                        color: AppColors.c34A853,
                      ),
                    ),
                  ),
                ],
              ),
            ],
          ).paddingSymmetric(horizontal: 16),
        ),
      ),
    );
  }
}
