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/utils/fields_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_colors.dart';
import 'package:uco_mobile_poc/app/res/app_dimensions.dart';

import '../../../core/constants/translation_keys.dart';
import '../../../custom_widgets/custom_dropdown.dart';
import '../../../custom_widgets/custom_input_field.dart';
import '../../../models/identity_drop_down_model.dart';
import '../../../res/app_theme.dart';
import '../controllers/sign_up_screen_step2_controller.dart';

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

  @override
  Widget build(BuildContext context) {
    var border = OutlineInputBorder(borderSide: const BorderSide(color: AppThemeData.inputEnabledBorderColor), borderRadius: BorderRadius.circular(50));
    var dropDowDecoration = InputDecoration(
      border: border,
      enabledBorder: border,
      focusedBorder: border,
      disabledBorder: border,
      errorBorder: border,
    );

    String className = runtimeType.toString().split('.').last;

    return Scaffold(
      appBar: DashBoardAppBar(
        title: TranslationKeys.makeTranslation(TranslationKeys.textSingUp),
        onBackButtonPressed: () {
          Get.back();
           controller.clearTextControllerStep2();
        },
      ),
      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: 12),
            buttonColor: AppColors.colorButton,
            textStyle: const TextStyle(color: AppColors.white),
          ),
        ),
      ],
      body: Padding(
        padding: EdgeInsets.symmetric(vertical: AppDimensions.screenVerticalPadding, horizontal: AppDimensions.screenHorizontalPadding),
        child: GetBuilder<SignUpScreenStep2Controller>(builder: (controller) {
          return SingleChildScrollView(
            child: Column(
              children: [
                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: "Enter first name",
                        labelText: TranslationKeys.makeTranslation(TranslationKeys.textFirstName),
                        inputFormatters: [LengthLimitingTextInputFormatter(FieldUtils.userNameFieldLength)],
                      ),
                    ),
                    const Spacer(),
                    Expanded(
                      flex: 8,
                      child: controller.lastNameField = InputField(
                        enableInteractiveSelection: false,
                        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.countryFeild = InputField(
                  refKey: FormFieldConstants.instance()
                      .getFormKey("${className}selectCountry"),
                  controller: FormFieldConstants.instance()
                      .getController("${className}selectCountry"),
                  labelText: "Select Country",
                  isDropDown: true,
                  hintText: "Select Country",
                  dropDownType: DropDownType.SPECIAL,
                  items: controller.countryList,
                  onItemSelected: (item) {
                    controller.selectedCountryCode = item?.id;
                    controller.update();
                  },
                  // onItemSelected: (item) {},
                ),

                controller.provinceFeild = InputField(
                  refKey: FormFieldConstants.instance()
                      .getFormKey("${className}provinceField"),
                  controller: FormFieldConstants.instance()
                      .getController("${className}provinceField"),
                  labelText: "Select Province",
                  isDropDown: true,
                  hintText: "Select Province",
                  dropDownType: DropDownType.SPECIAL,
                  items: controller.selectedCountryCode == null
                      ? []
                      : controller.getProvinceList(controller.selectedCountryCode!),
                  onItemSelected: (item) {},
                  // items: controller.getProvinceList('USA'),
                  // onItemSelected: (item) {
                  //   controller.selectedCountryCode = item?.id;
                  //   controller.update();
                  // },
                  // items: controller.getProvinceList("USA"),
                  // onItemSelected: (item) {},
                ),

                controller.cityFeild = InputField(
                  refKey: FormFieldConstants.instance()
                      .getFormKey("${className}cityField"),
                  controller: FormFieldConstants.instance()
                      .getController("${className}cityField"),
                  labelText: "Select City",
                  isDropDown: true,
                  hintText: "Select City",
                  dropDownType: DropDownType.SPECIAL,
                  items: controller.cityList,
                  onItemSelected: (item) {
                    controller.updateIdentityValue(item);
                  },
                ),

                controller.nameAddressField = InputField(
                  enableInteractiveSelection: false,
                  refKey: FormFieldConstants.instance().getFormKey("${className}nameAddressField"),
                  controller: FormFieldConstants.instance().getController("${className}nameAddressField"),
                  hintText: "Enter address",
                  labelText: TranslationKeys.makeTranslation(TranslationKeys.textAddress),
                  inputFormatters: [LengthLimitingTextInputFormatter(FieldUtils.addressFieldLength)],
                ),

                controller.currencyCodesFelid = InputField(
                  refKey: FormFieldConstants.instance().getFormKey("${className}currencyCodesFelid"),
                  controller: FormFieldConstants.instance().getController("${className}currencyCodesFelid"),
                  labelText: "Select Default Currency",
                  isDropDown: true,
                  hintText: "Select Default Currency",
                  dropDownType: DropDownType.SPECIAL,
                  items: controller.currencyListDropDown as List<DropDown>?,
                  onItemSelected: (item) {
                    controller.updateCurrency(item);
                  },
                ),

                controller.selectIdentityTypeField = InputField(
                  refKey: FormFieldConstants.instance().getFormKey("${className}selectIdentificationField"),
                  controller: FormFieldConstants.instance().getController("${className}selectIdentificationField"),
                  labelText: "Select Identification",
                  isDropDown: true,
                  hintText: "Select Identification",
                  dropDownType: DropDownType.SPECIAL,
                  items: controller.identityDropdownList,
                  onItemSelected: (item) {
                    controller.updateIdentityValue(item);
                  },
                ),

                Column(
                  children: [
                    Visibility(
                      visible: controller.currentIdentityValue?.id == controller.IDEN_NUMBER,
                      child: controller.identityNumberField = InputField(
                        enableInteractiveSelection: false,
                        refKey: FormFieldConstants.instance().getFormKey("${className}identityNumberField"),
                        controller: FormFieldConstants.instance().getController("${className}identityNumberField"),
                        labelText: TranslationKeys.makeTranslation(TranslationKeys.textIdentityNumber),
                        hintText: "Enter Identity number",
                        onSubmitted: (value) {
                          controller.validateAndSendRequest();
                        },
                      ),
                    ),
                    Visibility(
                      visible: controller.currentIdentityValue?.id == controller.IDEN_TAX_PAYER_ID,
                      child: controller.taxPayerIdField = InputField(
                        enableInteractiveSelection: false,
                        refKey: FormFieldConstants.instance().getFormKey("${className}taxPayerIdField"),
                        controller: FormFieldConstants.instance().getController("${className}taxPayerIdField"),
                        labelText: TranslationKeys.makeTranslation(TranslationKeys.textSSNTaxPayerID),
                        hintText: "Enter taxpayer id",
                        onSubmitted: (value) {
                          controller.validateAndSendRequest();
                        },
                      ),
                    ),
                    Visibility(
                      visible: controller.currentIdentityValue?.id == controller.IDEN_PASSPORT,
                      child: controller.passportField = InputField(
                        enableInteractiveSelection: false,
                        refKey: FormFieldConstants.instance().getFormKey("${className}passportField"),
                        controller: FormFieldConstants.instance().getController("${className}passportField"),
                        labelText: TranslationKeys.makeTranslation(TranslationKeys.textPassportAlienID),
                        hintText: "Enter passport number",
                        onSubmitted: (value) {
                          controller.validateAndSendRequest();
                        },
                      ),
                    ),
                  ],
                ),

                controller.currentIdentityValue?.id == identityType.identity
                    ? controller.identityNumberField = CustomInputFieldCustom(
                  refKey: FormFieldConstants.instance().getFormKey("${className}identityNumberField"),
                  controller: FormFieldConstants.instance().getController("${className}identityNumberField"),
                  labelText: TranslationKeys.makeTranslation(TranslationKeys.textIdentityNumber),
                ) as InputField
                    : const SizedBox(),
                controller.currentIdentityValue?.id == identityType.passport
                    ? controller.taxPayerIdField = CustomInputFieldCustom(
                  refKey: FormFieldConstants.instance().getFormKey("${className}taxPayerIdField"),
                  controller: FormFieldConstants.instance().getController("${className}taxPayerIdField"),
                  labelText: TranslationKeys.makeTranslation(TranslationKeys.textSSNTaxPayerID),
                ) as InputField
                    : const SizedBox(),
                controller.currentIdentityValue?.id == identityType.ssntaxpayer
                    ? controller.passportField = CustomInputFieldCustom(
                  refKey: FormFieldConstants.instance().getFormKey("${className}passportField"),
                  controller: FormFieldConstants.instance().getController("${className}passportField"),
                  labelText: TranslationKeys.makeTranslation(TranslationKeys.textPassportAlienID),
                ) as InputField
                    : const SizedBox(),
              ],
            ),
          );
        }),
      ),
    );
  }
}
