import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:hmg_patient_app_new/core/app_assets.dart';
import 'package:hmg_patient_app_new/core/dependencies.dart';
import 'package:hmg_patient_app_new/core/enums.dart';
import 'package:hmg_patient_app_new/core/utils/size_utils.dart';
import 'package:hmg_patient_app_new/core/utils/validation_utils.dart';
import 'package:hmg_patient_app_new/extensions/string_extensions.dart';
import 'package:hmg_patient_app_new/extensions/widget_extensions.dart';
import 'package:hmg_patient_app_new/features/authentication/authentication_view_model.dart';
import 'package:hmg_patient_app_new/features/medical_file/medical_file_view_model.dart';
import 'package:hmg_patient_app_new/generated/locale_keys.g.dart';
import 'package:hmg_patient_app_new/theme/colors.dart';
import 'package:hmg_patient_app_new/widgets/buttons/custom_button.dart';
import 'package:hmg_patient_app_new/widgets/dropdown/country_dropdown_widget.dart';
import 'package:hmg_patient_app_new/widgets/input_widget.dart';

class FamilyFileAddWidget extends StatelessWidget {
  final Function()? onVerificationPress;
  final String message;

  const FamilyFileAddWidget(this.onVerificationPress, this.message, {super.key});

  @override
  Widget build(BuildContext context) {
    AuthenticationViewModel authVm = getIt.get<AuthenticationViewModel>();
    MedicalFileViewModel? medicalVM = getIt.get<MedicalFileViewModel>();
    // TODO: implement build
    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      mainAxisAlignment: MainAxisAlignment.start,
      mainAxisSize: MainAxisSize.min,
      children: [
        message.toText16(color: AppColors.textColor, weight: FontWeight.w500),
        SizedBox(height: 20.h),
        Container(
          decoration: BoxDecoration(color: Colors.white, borderRadius: BorderRadius.circular(24)),
          padding: EdgeInsets.symmetric(horizontal: 16.h, vertical: 8.h),
          child: Column(
            children: [
              CustomCountryDropdown(
                countryList: CountryEnum.values,
                onCountryChange: authVm.onCountryChange,
              ).paddingOnly(top: 8.h, bottom: 16.h),
              Divider(height: 1.h, color: AppColors.spacerLineColor),
              TextInputWidget(
                labelText: LocaleKeys.nationalIdNumber.tr(),
                hintText: "xxxxxxxxx",
                controller: authVm.nationalIdController,
                isEnable: true,
                prefix: null,
                isAllowRadius: true,
                isBorderAllowed: false,
                isAllowLeadingIcon: true,
                autoFocus: true,
                keyboardType: TextInputType.number,
                padding: EdgeInsets.symmetric(vertical: 8.h),
                leadingIcon: AppAssets.student_card,
              ).paddingOnly(top: 8.h, bottom: 8.h),
              Divider(height: 1.h, color: AppColors.spacerLineColor),
              TextInputWidget(
                labelText: LocaleKeys.phoneNumber.tr(),
                hintText: "",
                controller: authVm.phoneNumberController,
                isEnable: true,
                prefix: authVm.selectedCountrySignup.countryCode,
                isAllowRadius: true,
                isBorderAllowed: false,
                isAllowLeadingIcon: true,
                autoFocus: true,
                keyboardType: TextInputType.number,
                padding: EdgeInsets.symmetric(vertical: 8.h),
                leadingIcon: AppAssets.smart_phone,
              ).paddingOnly(top: 8.h, bottom: 4.h),
            ],
          ),
        ),
        SizedBox(height: 20.h),
        CustomButton(
            text: "Verify the member".needTranslation,
            onPressed: () {
              FocusScope.of(context).unfocus();
              if (ValidationUtils.isValidatedIdAndPhoneWithCountryValidation(
                nationalId: authVm.nationalIdController.text,
                selectedCountry: authVm.selectedCountrySignup,
                phoneNumber: authVm.phoneNumberController.text,
                onOkPress: () {
                  Navigator.of(context).pop();
                },
              )) {
                // authVm.addFamilyMember(otpTypeEnum: OTPTypeEnum.sms, isExcludedUser: true);
                if (onVerificationPress != null) {
                  onVerificationPress!();
                }
              }
            },
            icon: AppAssets.add_icon,
            height: 56.h,
            fontWeight: FontWeight.w600),
        SizedBox(height: 20.h),
      ],
    );
  }
}
