import 'package:age_calculator/age_calculator.dart';
import 'package:flutter/material.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:intl/intl.dart';
import 'package:jiffy/jiffy.dart';
import 'package:mitra_corporate/app/constant.dart';
import 'package:mitra_corporate/model/registration_model.dart';
import 'package:mitra_corporate/provider/auth_provider.dart';
import 'package:mitra_corporate/screen/registrasi/get_filter_provider.dart';
import 'package:mitra_corporate/widgets/custom_snackbar_widget.dart';
import 'package:mitra_corporate/widgets/custom_text_field.dart';
import 'package:loading_animation_widget/loading_animation_widget.dart';

import '../../provider/registrasi_provider.dart';

class FormDataPasien extends HookConsumerWidget {
  const FormDataPasien({super.key});

  @override
  Widget build(BuildContext context, WidgetRef ref) {
    final tempPatient = ref.watch(registrationDataProvider);
    final auth = ref.watch(authProvider);
    //withoutnik apabila tanpa nik maka true
    final withoutNIK = useState(false);
    final getFilterLoading = useState(false);
    final sapaanKey = useState(1);
    final genderKey = useState(1000);
    final prefixCtr = useTextEditingController(text: "");
    final nameCtr = useTextEditingController(text: "");
    final suffixCtr = useTextEditingController(text: "");
    final nikCtr = useTextEditingController(text: "");
    final nipCtr = useTextEditingController(text: "");
    final hpCtr = useTextEditingController(text: "");
    final noRmCtr = useTextEditingController(text: "");
    final addressCtr = useTextEditingController(text: "");
    final diagnosisCtr = useTextEditingController(text: "");
    final noteCtr = useTextEditingController(text: "");
    final jabatanCtr = useTextEditingController(text: "");
    final kedudukanCtr = useTextEditingController(text: "");
    final lokasiCtr = useTextEditingController(text: "");
    final pekerjaanCtr = useTextEditingController(text: "");
    final sapaan = useState<List<CustomDropDownModel>>(List.empty());
    final selectedSaluation = useState(CustomDropDownModel());
    final gender = useState<List<CustomDropDownModel>>(List.empty());
    final selectedGender = useState(CustomDropDownModel());

    //select salah satu sapaan
    onSelectSaluation(CustomDropDownModel value) {
      selectedSaluation.value = value;
      selectedGender.value =
          gender.value.firstWhere((element) => element.id == value.type);

      genderKey.value = genderKey.value + 1;
      // sapaanKey.value = sapaanKey.value + 1;
    }

    //update gender saat sapaan dipilih
    selectedSaluation.addListener(() {
      selectedGender.value = gender.value
          .firstWhere((element) => element.id == selectedSaluation.value.type);
      genderKey.value = genderKey.value + 1;
    });

    //select gender
    onSelectGender(CustomDropDownModel value) {
      selectedGender.value = value;
    }

    final dobRb = useState('date');
    final dobCtr = useTextEditingController(
        text: DateFormat('dd-MM-yyyy').format(DateTime.now()));
    final dobState = useState(DateTime.now());

    final yearCtr = useTextEditingController(text: "0");
    final monthCtr = useTextEditingController(text: "0");
    final dayCtr = useTextEditingController(text: "0");

    //perhitungan umur dari tanggal ke angka
    DateDuration calculateAge(DateTime birthDate) {
      DateTime currentDate = DateTime.now();
      var age = AgeCalculator.age(birthDate, today: currentDate);
      return age;
    }

    dobState.addListener(
      () {
        // print(calculateAge(dobState.value));
        if (dobRb.value == "date") {
          var age = calculateAge(dobState.value);
          yearCtr.text = age.years.toString();
          monthCtr.text = age.months.toString();
          dayCtr.text = age.days.toString();
        }
      },
    );
    useEffect(() {
      WidgetsBinding.instance.addPostFrameCallback((timeStamp) async {
        nameCtr.text = tempPatient.patientData?.name ?? "";
        prefixCtr.text = tempPatient.patientData?.prefix ?? "";
        suffixCtr.text = tempPatient.patientData?.suffix ?? "";
        nikCtr.text = tempPatient.patientData?.nik ?? "";
        nipCtr.text = tempPatient.patientData?.nip ?? "";
        withoutNIK.value =
            tempPatient.patientData?.withoutNIK == 'Y' ? true : false;
        hpCtr.text = tempPatient.patientData?.hp ?? "";
        addressCtr.text = tempPatient.patientData?.address ?? "";
        diagnosisCtr.text = tempPatient.patientData?.diagnosis ?? "";
        noteCtr.text = tempPatient.patientData?.note ?? "";
        noRmCtr.text = tempPatient.patientData?.noRM ?? "";
        jabatanCtr.text = tempPatient.patientData?.jabatan ?? "";
        kedudukanCtr.text = tempPatient.patientData?.kedudukan ?? "";
        lokasiCtr.text = tempPatient.patientData?.lokasi ?? "";
        pekerjaanCtr.text = tempPatient.patientData?.pekerjaan ?? "";
        //  DateFormat('dd-MM-yyyy').format(DateTime.now())
        dobCtr.text = DateFormat('dd-MM-yyyy').format(DateTime.parse(
            tempPatient.patientData?.dob ?? DateTime.now().toString()));
        dobState.value = DateTime.parse(
            tempPatient.patientData?.dob ?? DateTime.now().toString());
        ref
            .read(GetFilterRegistrationProvider.notifier)
            .getData(token: auth!.token ?? "");
      });
      return () {};
    }, []);

    ref.listen(
      GetFilterRegistrationProvider,
      (previous, next) {
        if (next is GetFilterRegistrationStateInit) {
          getFilterLoading.value = true;
        } else if (next is GetFilterRegistrationStateLoading) {
          getFilterLoading.value = true;
        } else if (next is GetFilterRegistrationStateError) {
          SanckbarWidget(context, next.message, snackbarType.error);
          getFilterLoading.value = false;
          Constant.autoLogout(context: context, msg: next.message);
        } else if (next is GetFilterRegistrationStateDone) {
          // print(jsonEncode(next.model));
          sapaan.value = next.model.titles!;
          gender.value = next.model.gender!;
          // selectedGender.value = next.model.gender![0];
          if (tempPatient.patientData?.saluation != null) {
            var sp = next.model.titles!.firstWhere(
                (element) => element.id == tempPatient.patientData?.saluation);
            selectedSaluation.value = sp;
          }
          if (tempPatient.patientData?.gender != null) {
            var gd = next.model.gender!.firstWhere(
                (element) => element.id == tempPatient.patientData?.gender);
            selectedGender.value = gd;
          }
          sapaanKey.value = sapaanKey.value + 1;
          genderKey.value = genderKey.value + 1;
          getFilterLoading.value = false;
        }
      },
    );

    //Function ke step selanjutny(pilih pemeriksaan)
    nextStep() {
      if (withoutNIK.value == false) {
        if (nikCtr.text.isEmpty) {
          SanckbarWidget(context, "NIK Harus diisi", snackbarType.warning);
          return;
        }
        if (nikCtr.text.length < 16 || nikCtr.text.length > 16) {
          SanckbarWidget(
              context, "NIK berjumlah 16 digit", snackbarType.warning);
          return;
        }
      }

      if (nameCtr.text.isEmpty ||
          selectedGender.value.id == null ||
          selectedSaluation.value.id == null ||
          jabatanCtr.text.isEmpty ||
          kedudukanCtr.text.isEmpty ||
          lokasiCtr.text.isEmpty ||
          pekerjaanCtr.text.isEmpty) {
        // print(nameCtr.text);
        // print(selectedGender.value.name);
        SanckbarWidget(
            context,
            "Sapaan, Nama, Tanggal Lahir, Jenis Kelamin, jabatan, kedudukan, lokasi, dan pekerjaan Harus Diisi !",
            snackbarType.warning);
      } else {
        var temp = ref.watch(registrationDataProvider);
        PatientData data = PatientData(
            noRM: noRmCtr.text,
            saluation: selectedSaluation.value.id,
            name: nameCtr.text,
            prefix: prefixCtr.text,
            suffix: suffixCtr.text,
            dob: dobState.value.toString(),
            nik: nikCtr.text,
            nip: nipCtr.text,
            withoutNIK: withoutNIK.value ? "Y" : "N",
            gender: selectedGender.value.id.toString(),
            address: addressCtr.text,
            diagnosis: diagnosisCtr.text,
            hp: hpCtr.text,
            jabatan: jabatanCtr.text,
            kedudukan: kedudukanCtr.text,
            lokasi: lokasiCtr.text,
            pekerjaan: pekerjaanCtr.text,
            note: noteCtr.text);
        ref.read(registrationDataProvider.notifier).state = RegistrationModel(
            orderID: temp.orderID,
            token: auth?.token ?? "",
            patientId: temp.patientId ?? "new",
            patientData: data,
            specimens: temp.specimens,
            paket: temp.paket,
            bahan: temp.bahan,
            tests: temp.tests,
            total: temp.total);
        ref.read(registrasiProvider.state).update((state) => 1);
      }
    }

    return Padding(
      padding: const EdgeInsets.only(top: 20, bottom: 20, left: 24, right: 24),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Row(
            children: [
              SizedBox(
                  width: Constant.getActualX(context: context, x: 120),
                  child: Stack(
                    alignment: AlignmentDirectional.topEnd,
                    children: [
                      Padding(
                        padding: const EdgeInsets.all(5),
                        child: Text(
                          "*",
                          style: Constant.body2_400(context: context)
                              .copyWith(color: Constant.primaryRed),
                        ),
                      ),
                      DropdownMenu<CustomDropDownModel>(
                          menuHeight:
                              Constant.getActualY(context: context, y: 300),
                          key: ValueKey(sapaanKey.value),
                          initialSelection: selectedSaluation.value,
                          trailingIcon: getFilterLoading.value
                              ? LoadingAnimationWidget.discreteCircle(
                                  color: Constant.primaryBlue, size: 20)
                              : null,
                          width: Constant.getActualX(context: context, x: 120),
                          hintText: "Sapaan",
                          textStyle: Constant.body2_400(context: context),
                          inputDecorationTheme: InputDecorationTheme(
                              border: OutlineInputBorder(
                            borderSide: BorderSide(color: Constant.primaryBlue),
                            borderRadius: BorderRadius.circular(8),
                          )),
                          label: const Text(
                            "Sapaan",
                            maxLines: 1,
                            overflow: TextOverflow.ellipsis,
                          ),
                          onSelected: (value) {
                            onSelectSaluation(value!);
                            selectedSaluation.value = value;
                          },
                          dropdownMenuEntries: sapaan.value
                              .map<DropdownMenuEntry<CustomDropDownModel>>(
                                  (e) => DropdownMenuEntry(
                                      value: e, label: e.name ?? ""))
                              .toList()),
                    ],
                  )),
              SizedBox(width: Constant.getActualX(context: context, x: 24)),
              SizedBox(
                width: Constant.getActualX(context: context, x: 160),
                // height: Constant.getActualY(context: context, y: 56),
                child: CustomTextField(
                  hintText: 'Prefix',
                  labelText: "Prefix",
                  controller: prefixCtr,
                ),
              ),
              SizedBox(width: Constant.getActualX(context: context, x: 24)),
              SizedBox(
                width: Constant.getActualX(context: context, x: 520),
                // height: Constant.getActualY(context: context, y: 56),
                child: Stack(
                  alignment: AlignmentDirectional.topEnd,
                  children: [
                    Padding(
                      padding: const EdgeInsets.all(5),
                      child: Text(
                        "*",
                        style: Constant.body2_400(context: context)
                            .copyWith(color: Constant.primaryRed),
                      ),
                    ),
                    CustomTextField(
                      hintText: 'Name',
                      labelText: "Nama",
                      controller: nameCtr,
                    ),
                  ],
                ),
              ),
              SizedBox(width: Constant.getActualX(context: context, x: 24)),
              SizedBox(
                width: Constant.getActualX(context: context, x: 160),
                // height: Constant.getActualY(context: context, y: 56),
                child: CustomTextField(
                  hintText: 'Suffix',
                  labelText: "suffix",
                  controller: suffixCtr,
                ),
              ),
            ],
          ),
          SizedBox(height: Constant.getActualY(context: context, y: 24)),
          Row(
            children: [
              Radio<String>(
                value: "date",
                groupValue: dobRb.value,
                onChanged: (value) {
                  dobRb.value = value!;
                },
              ),
              SizedBox(width: Constant.getActualX(context: context, x: 20)),
              SizedBox(
                width: Constant.getActualX(context: context, x: 252),
                // height: Constant.getActualY(context: context, y: 56),
                child: Stack(
                  alignment: AlignmentDirectional.topEnd,
                  children: [
                    Padding(
                      padding: const EdgeInsets.all(5),
                      child: Text(
                        "*",
                        style: Constant.body2_400(context: context)
                            .copyWith(color: Constant.primaryRed),
                      ),
                    ),
                    TextField(
                      enabled: dobRb.value != "age",
                      controller: dobCtr,
                      style: Constant.body2_400(context: context),
                      decoration: InputDecoration(
                          suffixIcon: Icon(Icons.calendar_today),
                          border: OutlineInputBorder(
                            borderSide: BorderSide(color: Constant.primaryBlue),
                            borderRadius: BorderRadius.circular(8),
                          ),
                          labelText: "Tanggal Lahir" //label text of field
                          ),
                      readOnly: true,
                      onTap: () async {
                        DateTime? pickedDate = await showDatePicker(
                            // locale: Locale("id"),
                            context: context,
                            initialDate: dobState.value,
                            firstDate: DateTime(1800),
                            initialEntryMode: DatePickerEntryMode.calendarOnly,

                            //DateTime.now() - not to allow to choose before today.
                            lastDate: DateTime(2100));

                        if (pickedDate != null) {
                          print(
                              pickedDate); //pickedDate output format => 2021-03-10 00:00:00.000
                          String formattedDate =
                              DateFormat('dd-MM-yyyy').format(pickedDate);
                          print(
                              formattedDate); //formatted date output using intl package =>  2021-03-16
                          dobCtr.text =
                              formattedDate; //set output date to TextField value.
                          dobState.value = pickedDate;
                        } else {}
                      },
                    ),
                  ],
                ),
              ),
              SizedBox(width: Constant.getActualX(context: context, x: 24)),
              Radio<String>(
                value: "age",
                groupValue: dobRb.value,
                onChanged: (value) {
                  dobRb.value = value!;
                },
              ),
              SizedBox(width: Constant.getActualX(context: context, x: 20)),
              Stack(
                clipBehavior: Clip.none,
                // alignment: AlignmentDirectional.bottomCenter,
                children: [
                  Container(
                    padding: EdgeInsets.symmetric(
                        horizontal:
                            Constant.getActualX(context: context, x: 16),
                        vertical: Constant.getActualY(context: context, y: 12)),
                    decoration: BoxDecoration(
                        borderRadius: BorderRadius.circular(8),
                        border: Border.all(color: Colors.grey)),
                    child: Row(
                      children: [
                        SizedBox(
                          width: Constant.getActualX(context: context, x: 90),
                          height: Constant.getActualY(context: context, y: 40),
                          child: CustomTextField(
                            onChange: (value) {
                              if (dobRb.value == "age") {
                                DateTime coba = Jiffy.now()
                                    .subtract(
                                        months: int.parse(monthCtr.text),
                                        years: int.parse(yearCtr.text),
                                        days: int.parse(dayCtr.text))
                                    .dateTime;
                                // print(coba);
                                dobState.value = coba;
                                dobCtr.text = DateFormat('dd-MM-yyyy')
                                    .format(dobState.value);
                              }
                            },
                            disable: dobRb.value != "date",
                            hintText: 'Tahun',
                            labelText: "",
                            isDense: true,
                            suffixIcon: SizedBox(
                              child: Container(
                                padding: EdgeInsets.only(
                                  top: Constant.getActualY(
                                      context: context, y: 8),
                                  bottom: Constant.getActualY(
                                      context: context, y: 8),
                                  right: Constant.getActualX(
                                      context: context, x: 5),
                                ),
                                child: Text(
                                  'Tahun',
                                  style: Constant.body3_400(context: context)
                                      .copyWith(color: Colors.grey),
                                ),
                              ),
                            ),
                            style: Constant.body3_400(context: context),
                            hintStyle: Constant.body3_400(context: context),
                            labelStyle: Constant.body3_400(context: context),
                            controller: yearCtr,
                            inputType: TextInputType.number,
                          ),
                        ),
                        SizedBox(
                            width:
                                Constant.getActualX(context: context, x: 16)),
                        SizedBox(
                          width: Constant.getActualX(context: context, x: 90),
                          height: Constant.getActualY(context: context, y: 40),
                          child: CustomTextField(
                            onChange: (value) {
                              if (dobRb.value == "age") {
                                DateTime currentDate = DateTime.now();
                                DateTime coba = Jiffy.now()
                                    .subtract(
                                        months: int.parse(monthCtr.text),
                                        years: int.parse(yearCtr.text),
                                        days: int.parse(dayCtr.text))
                                    .dateTime;
                                // print(coba);

                                dobState.value = coba;
                                dobCtr.text = DateFormat('dd-MM-yyyy')
                                    .format(dobState.value);
                              }
                            },
                            disable: dobRb.value != "date",
                            hintText: 'Bulan',
                            labelText: "",
                            controller: monthCtr,
                            inputType: TextInputType.number,
                            isDense: true,
                            suffixIcon: Container(
                              child: Container(
                                padding: EdgeInsets.only(
                                  top: Constant.getActualY(
                                      context: context, y: 8),
                                  bottom: Constant.getActualY(
                                      context: context, y: 8),
                                  right: Constant.getActualX(
                                      context: context, x: 5),
                                ),
                                child: Text(
                                  'Bulan',
                                  style: Constant.body3_400(context: context)
                                      .copyWith(color: Colors.grey),
                                ),
                              ),
                            ),
                            style: Constant.body3_400(context: context),
                            hintStyle: Constant.body3_400(context: context),
                            labelStyle: Constant.body3_400(context: context),
                          ),
                        ),
                        SizedBox(
                            width:
                                Constant.getActualX(context: context, x: 16)),
                        SizedBox(
                          width: Constant.getActualX(context: context, x: 90),
                          height: Constant.getActualY(context: context, y: 40),
                          child: CustomTextField(
                            disable: dobRb.value != "date",
                            onChange: (value) {
                              if (dobRb.value == "age") {
                                if (int.parse(dayCtr.text) <= 31) {
                                  DateTime currentDate = DateTime.now();

                                  DateTime coba = Jiffy.now()
                                      .subtract(
                                          months: int.parse(monthCtr.text),
                                          years: int.parse(yearCtr.text),
                                          days: int.parse(dayCtr.text))
                                      .dateTime;
                                  // print(coba);

                                  dobState.value = coba;
                                  dobCtr.text = DateFormat('dd-MM-yyyy')
                                      .format(dobState.value);
                                } else {
                                  dayCtr.text = "31";
                                  SanckbarWidget(
                                      context,
                                      "hari tidak lebih dari 31",
                                      snackbarType.warning);
                                }
                              }
                            },
                            hintText: 'Hari',
                            labelText: "",
                            controller: dayCtr,
                            inputType: TextInputType.number,
                            isDense: true,
                            suffixIcon: Container(
                              child: Container(
                                padding: EdgeInsets.only(
                                  top: Constant.getActualY(
                                      context: context, y: 8),
                                  bottom: Constant.getActualY(
                                      context: context, y: 8),
                                  right: Constant.getActualX(
                                      context: context, x: 5),
                                ),
                                child: Text(
                                  'Hari',
                                  style: Constant.body3_400(context: context)
                                      .copyWith(color: Colors.grey),
                                ),
                              ),
                            ),
                            style: Constant.body3_400(context: context),
                            hintStyle: Constant.body3_400(context: context),
                            labelStyle: Constant.body3_400(context: context),
                          ),
                        ),
                      ],
                    ),
                  ),
                  Positioned(
                      top: -8,
                      left: 10,
                      child: Container(
                          color: Colors.white,
                          child: const Text(
                            "Umur",
                            style: TextStyle(color: Colors.grey),
                          )))
                ],
              ),
              SizedBox(width: Constant.getActualX(context: context, x: 24)),
              SizedBox(
                width: Constant.getActualX(context: context, x: 300),
                // height: Constant.getActualY(context: context, y: 56),
                child: CustomTextField(
                  hintText: 'No RM',
                  labelText: "No RM",
                  controller: noRmCtr,
                ),
              )
            ],
          ),
          SizedBox(height: Constant.getActualY(context: context, y: 24)),
          Row(
            children: [
              SizedBox(
                width: Constant.getActualX(context: context, x: 240),
                // height: Constant.getActualY(context: context, y: 56),
                child: Stack(
                  alignment: AlignmentDirectional.topEnd,
                  children: [
                    Padding(
                      padding: const EdgeInsets.all(5),
                      child: Text(
                        "*",
                        style: Constant.body2_400(context: context)
                            .copyWith(color: Constant.primaryRed),
                      ),
                    ),
                    CustomTextField(
                        inputType: TextInputType.number,
                        controller: nikCtr,
                        hintText: withoutNIK.value
                            ? "Pasien Tanpa NIK Data Historis Tidak Terkonsolidasi"
                            : 'NIK',
                        labelText: withoutNIK.value
                            ? "Pasien Tanpa NIK Data Historis Tidak Terkonsolidasi"
                            : "NIK"),
                  ],
                ),
              ),
              SizedBox(width: Constant.getActualX(context: context, x: 20)),
              Center(
                child: Transform.scale(
                  scale: 0.8,
                  child: Checkbox(
                      shape: RoundedRectangleBorder(
                          borderRadius: BorderRadius.circular(4)),
                      value: withoutNIK.value,
                      onChanged: (value) {
                        withoutNIK.value = value!;
                        if (value == true) {}
                      }),
                ),
              ),
              Text('Tanpa NIK',
                  style: Constant.body2_400(context: context)
                      .copyWith(color: Constant.textBlack)),
              // SizedBox(width: Constant.getActualX(context: context, x: 24)),
              // SizedBox(
              //     width: Constant.getActualX(context: context, x: 250),
              //     child: DropdownMenu<CustomDropDownModel>(
              //         key: ValueKey(genderKey.value),
              //         initialSelection: selectedGender.value,
              //         trailingIcon: getFilterLoading.value
              //             ? LoadingAnimationWidget.discreteCircle(
              //                 color: Constant.primaryBlue, size: 20)
              //             : null,
              //         width: Constant.getActualX(context: context, x: 250),
              //         hintText: "Jenis Kelamin",
              //         textStyle: Constant.body2_400(context: context),
              //         inputDecorationTheme: InputDecorationTheme(
              //             border: OutlineInputBorder(
              //           borderSide: BorderSide(color: Constant.primaryBlue),
              //           borderRadius: BorderRadius.circular(8),
              //         )),
              //         label: const Text("jenis Kelamin"),
              //         onSelected: (value) {
              //           onSelectGender(value!);
              //           selectedGender.value = value;
              //         },
              //         dropdownMenuEntries: gender.value
              //             .map<DropdownMenuEntry<CustomDropDownModel>>((e) =>
              //                 DropdownMenuEntry(value: e, label: e.name ?? ""))
              //             .toList())),
              // SizedBox(width: Constant.getActualX(context: context, x: 24)),
              // SizedBox(
              //   width: Constant.getActualX(context: context, x: 365),
              //   // height: Constant.getActualY(context: context, y: 56),
              //   child: CustomTextField(
              //     hintText: 'No Hp',
              //     labelText: "No Hp",
              //     controller: hpCtr,
              //   ),
              // ),
            ],
          ),
          SizedBox(height: Constant.getActualY(context: context, y: 24)),
          Row(
            children: [
              SizedBox(
                  width: Constant.getActualX(context: context, x: 304),
                  child: Stack(
                    alignment: AlignmentDirectional.topEnd,
                    children: [
                      Padding(
                        padding: const EdgeInsets.all(5),
                        child: Text(
                          "*",
                          style: Constant.body2_400(context: context)
                              .copyWith(color: Constant.primaryRed),
                        ),
                      ),
                      DropdownMenu<CustomDropDownModel>(
                          key: ValueKey(genderKey.value),
                          initialSelection: selectedGender.value,
                          trailingIcon: getFilterLoading.value
                              ? LoadingAnimationWidget.discreteCircle(
                                  color: Constant.primaryBlue, size: 20)
                              : null,
                          width: Constant.getActualX(context: context, x: 304),
                          hintText: "Jenis Kelamin",
                          textStyle: Constant.body2_400(context: context),
                          inputDecorationTheme: InputDecorationTheme(
                              border: OutlineInputBorder(
                            borderSide: BorderSide(color: Constant.primaryBlue),
                            borderRadius: BorderRadius.circular(8),
                          )),
                          label: const Text("jenis Kelamin"),
                          onSelected: (value) {
                            onSelectGender(value!);
                            selectedGender.value = value;
                          },
                          dropdownMenuEntries: gender.value
                              .map<DropdownMenuEntry<CustomDropDownModel>>(
                                  (e) => DropdownMenuEntry(
                                      value: e, label: e.name ?? ""))
                              .toList()),
                    ],
                  )),
              SizedBox(width: Constant.getActualX(context: context, x: 24)),
              SizedBox(
                width: Constant.getActualX(context: context, x: 218),
                // height: Constant.getActualY(context: context, y: 56),
                child: CustomTextField(
                  inputType: TextInputType.number,
                  hintText: 'No Hp',
                  labelText: "No Hp",
                  controller: hpCtr,
                ),
              ),
              SizedBox(
                width: Constant.getActualX(context: context, x: 24),
              ),
              SizedBox(
                width: Constant.getActualX(context: context, x: 218),
                child: CustomTextField(
                  hintText: "NIP",
                  labelText: "NIP",
                  controller: nipCtr,
                ),
              ),
            ],
          ),
          // SizedBox(height: Constant.getActualY(context: context, y: 24)),
          // Row(
          //   children: [],
          // ),
          SizedBox(height: Constant.getActualY(context: context, y: 24)),
          Row(
            children: [
              SizedBox(
                width: Constant.getActualX(context: context, x: 304),
                // height: Constant.getActualY(context: context, y: 56),
                child: Stack(
                  alignment: AlignmentDirectional.topEnd,
                  children: [
                    Padding(
                      padding: const EdgeInsets.all(5),
                      child: Text(
                        "*",
                        style: Constant.body2_400(context: context)
                            .copyWith(color: Constant.primaryRed),
                      ),
                    ),
                    CustomTextField(
                      hintText: 'Jabatan',
                      labelText: "Jabatan",
                      controller: jabatanCtr,
                    ),
                  ],
                ),
              ),
              SizedBox(width: Constant.getActualX(context: context, x: 24)),
              SizedBox(
                width: Constant.getActualX(context: context, x: 218),
                // height: Constant.getActualY(context: context, y: 56),
                child: Stack(
                  alignment: AlignmentDirectional.topEnd,
                  children: [
                    Padding(
                      padding: const EdgeInsets.all(5),
                      child: Text(
                        "*",
                        style: Constant.body2_400(context: context)
                            .copyWith(color: Constant.primaryRed),
                      ),
                    ),
                    CustomTextField(
                      hintText: 'Kedudukan',
                      labelText: "Kedudukan",
                      controller: kedudukanCtr,
                    ),
                  ],
                ),
              ),
              SizedBox(width: Constant.getActualX(context: context, x: 24)),
              SizedBox(
                width: Constant.getActualX(context: context, x: 218),
                // height: Constant.getActualY(context: context, y: 56),
                child: Stack(
                  alignment: AlignmentDirectional.topEnd,
                  children: [
                    Padding(
                      padding: const EdgeInsets.all(5),
                      child: Text(
                        "*",
                        style: Constant.body2_400(context: context)
                            .copyWith(color: Constant.primaryRed),
                      ),
                    ),
                    CustomTextField(
                      hintText: 'Lokasi',
                      labelText: "Lokasi",
                      controller: lokasiCtr,
                    ),
                  ],
                ),
              ),
              SizedBox(width: Constant.getActualX(context: context, x: 24)),
              SizedBox(
                width: Constant.getActualX(context: context, x: 218),
                // height: Constant.getActualY(context: context, y: 56),
                child: Stack(
                  alignment: AlignmentDirectional.topEnd,
                  children: [
                    Padding(
                      padding: const EdgeInsets.all(5),
                      child: Text(
                        "*",
                        style: Constant.body2_400(context: context)
                            .copyWith(color: Constant.primaryRed),
                      ),
                    ),
                    CustomTextField(
                      hintText: 'Pekerjaan',
                      labelText: "Pekerjaan",
                      controller: pekerjaanCtr,
                    ),
                  ],
                ),
              )
            ],
          ),
          SizedBox(height: Constant.getActualY(context: context, y: 24)),
          SizedBox(
            width: Constant.getActualX(context: context, x: 1032),
            // height: Constant.getActualY(context: context, y: 120),
            child: CustomTextField(
                controller: addressCtr,
                hintText: 'Alamat',
                labelText: "Alamat",
                maxLines: 4,
                minLines: 1),
          ),
          SizedBox(height: Constant.getActualY(context: context, y: 24)),
          SizedBox(
            width: Constant.getActualX(context: context, x: 1032),
            // height: Constant.getActualY(context: context, y: 120),
            child: CustomTextField(
                controller: diagnosisCtr,
                hintText: 'Diagnosis',
                labelText: "Diagnosis",
                maxLines: 4,
                minLines: 1),
          ),
          SizedBox(height: Constant.getActualY(context: context, y: 24)),
          SizedBox(
            width: Constant.getActualX(context: context, x: 1032),
            // height: Constant.getActualY(context: context, y: 120),
            child: CustomTextField(
                controller: noteCtr,
                hintText: 'Catatan FO',
                labelText: "Catatan FO",
                maxLines: 4,
                minLines: 1),
          ),
          SizedBox(height: Constant.getActualY(context: context, y: 24)),
          SizedBox(
            child: Row(
              mainAxisAlignment: MainAxisAlignment.end,
              children: [
                OutlinedButton(
                    style: OutlinedButton.styleFrom(
                        backgroundColor: Colors.white,
                        side: BorderSide(color: Colors.grey.shade400, width: 2),
                        shape: RoundedRectangleBorder(
                            borderRadius: BorderRadius.circular(8))),
                    onPressed: () {
                      ref.read(registrationDataProvider.notifier).state =
                          RegistrationModel();
                      ref.read(selectedTestProvider.notifier).state =
                          List.empty(growable: true);
                      ref.read(selectedPacketProvider.notifier).state =
                          List.empty(growable: true);
                      Navigator.pop(context);
                    },
                    child: SizedBox(
                      height: Constant.getActualY(context: context, y: 56),
                      child: Center(
                        child: Text('Batal',
                            style: Constant.button_medium(context: context)
                                .copyWith(color: Constant.textBlack)),
                      ),
                    )),
                SizedBox(width: Constant.getActualX(context: context, x: 24)),
                ElevatedButton(
                    style: ElevatedButton.styleFrom(
                      backgroundColor: Constant.green,
                      side: BorderSide(color: Constant.green, width: 2),
                      shape: RoundedRectangleBorder(
                        borderRadius: BorderRadius.circular(8),
                      ),
                    ),
                    onPressed: () {
                      nextStep();
                    },
                    child: SizedBox(
                      height: Constant.getActualY(context: context, y: 56),
                      child: Center(
                        child: Text('Berikutnya',
                            style: Constant.body3_600(context: context)
                                .copyWith(color: Constant.textWhite)),
                      ),
                    )),
              ],
            ),
          )
        ],
      ),
    );
  }
}
