import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:get/get.dart';
import 'package:uco_mobile_poc/app/core/constants/form_field_constants.dart';
import 'package:uco_mobile_poc/app/core/data/data_source_auth/remote_data_source/app_remote_data_source.dart';
import 'package:uco_mobile_poc/app/core/data/repositories/app_repositories.dart';
import 'package:uco_mobile_poc/app/core/utils/fields_utils.dart';
import 'package:uco_mobile_poc/app/core/utils/phone_number_utils.dart';
import 'package:uco_mobile_poc/app/custom_widgets/Fields/input_field.dart';
import 'package:uco_mobile_poc/app/custom_widgets/custom_app_bar.dart';
import 'package:uco_mobile_poc/app/custom_widgets/custom_button.dart';
import 'package:uco_mobile_poc/app/res/app_dimensions.dart';

import '../../../core/constants/translation_keys.dart';
import '../../../core/utils/app_utils.dart';
import '../../../res/app_colors.dart';
import '../controllers/sign_up_screen_step1_controller.dart';

class SignUpScreenStep1View extends GetView<SignUpScreenStep1Controller> {
  const SignUpScreenStep1View({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    // Get.put(() => AppRemoteDataSource());
    // Get.lazyPut<AppRepositories>(() => AppRepositoriesImpl(remoteDataSource: Get.find<AppRemoteDataSource>()));
    String className = runtimeType.toString().split('.').last;
    return Scaffold(
      appBar: DashBoardAppBar(
        title: TranslationKeys.makeTranslation(TranslationKeys.textSingUp),
        onBackButtonPressed: () {
          if (Navigator.canPop(context)) {
            Get.back();
            controller.clearTextControllerStep1();
          } else {
            SystemNavigator.pop();
          }
        },
      ),
      persistentFooterButtons: [
        Padding(
          padding: EdgeInsets.symmetric(vertical: AppDimensions.screenVerticalPadding, horizontal: AppDimensions.screenHorizontalPadding),
          child: CustomButton(
            onPressed: () {
              controller.validateAndSendRequest();
            },
            buttonText: TranslationKeys.makeTranslation(TranslationKeys.textNext),
            buttonPadding: const EdgeInsets.symmetric(
              vertical: 10,
            ),
            buttonColor: AppColors.colorButton,
            textStyle: const TextStyle(color: AppColors.white),
          ),
        ),
      ],
      body: SingleChildScrollView(
        child: Padding(
          padding: EdgeInsets.symmetric(vertical: AppDimensions.screenVerticalPadding, horizontal: AppDimensions.screenHorizontalPadding),
          child: Column(
            children: [
              const SizedBox(height: 10),
              Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: [
                  Expanded(
                    flex: 8,
                    child: controller.firstNameField = InputField(
                      enableInteractiveSelection: false,
                      refKey: FormFieldConstants.instance().getFormKey("${className}firstNameField"),
                      controller: FormFieldConstants.instance().getController("${className}firstNameField"),
                      hintText: "First Name",
                      labelText: TranslationKeys.makeTranslation("First Name"),
                      inputFormatters: [LengthLimitingTextInputFormatter(FieldUtils.userNameFieldLength)],
                    )
                  ),
                  const Spacer(),
                  Expanded(
                    flex: 8,
                    child: controller.lastNameField = InputField(
                      refKey: FormFieldConstants.instance().getFormKey("${className}lastNameField"),
                      controller: FormFieldConstants.instance().getController("${className}lastNameField"),
                      hintText: "Enter last name",
                      labelText: TranslationKeys.makeTranslation(TranslationKeys.textLastName),
                      inputFormatters: [LengthLimitingTextInputFormatter(FieldUtils.userNameFieldLength)],
                    ),
                  ),
                ],
              ),
              controller.passwordField = InputField(
                enableInteractiveSelection: false,
                refKey: FormFieldConstants.instance().getFormKey("${className}passwordField"),
                controller: FormFieldConstants.instance().getController("${className}passwordField"),
                hintText: "Enter password",
                labelText: TranslationKeys.makeTranslation(TranslationKeys.textPassword),
                keyboardType: TextInputType.visiblePassword,
                requiredPasswordIcon: true,
                isPassword: true,
              ),
              controller.confirmPasswordField = InputField(
                enableInteractiveSelection: false,
                refKey: FormFieldConstants.instance().getFormKey("${className}confirmPasswordField"),
                controller: FormFieldConstants.instance().getController("${className}confirmPasswordField"),
                hintText: "Enter password",
                labelText: TranslationKeys.makeTranslation(TranslationKeys.textConfirmPassword),
                keyboardType: TextInputType.visiblePassword,
                requiredPasswordIcon: true,
                isPassword: true,
              ),
              controller.emailField = InputField(
                enableInteractiveSelection: false,
                refKey: FormFieldConstants.instance().getFormKey("${className}emailField"),
                controller: FormFieldConstants.instance().getController("${className}emailField"),
                hintText: "Enter email",
                labelText: TranslationKeys.makeTranslation(TranslationKeys.textEmailID),
              ),
              controller.phoneNumberField = InputField(
                enableInteractiveSelection: false,
                refKey: FormFieldConstants.instance().getFormKey("${className}phoneNumberField"),
                controller: FormFieldConstants.instance().getController("${className}phoneNumberField"),
                hintText: "Enter phone number",
                labelText: TranslationKeys.makeTranslation(TranslationKeys.textCellNumber),
                keyboardType: TextInputType.phone,
                inputFormatters: [LengthLimitingTextInputFormatter(PhoneNumberUtils.getPhoneNumberLength()), InputType.NUMBER],
                // prefixText:AppUtils.formatPhoneNumber(PhoneNumberUtils.phoneCode),
                prefixCode: PhoneNumberUtils.phoneCode,
                onSubmitted: (value) {
                  controller.validateAndSendRequest();
                },
                isCountryPicker: true,
              ),
            ],
          ),
        ),
      ),
    );
  }
}
