// ignore_for_file: unnecessary_null_comparison

import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:intl/intl.dart';
import 'package:service/views/widgets/my_scafold.dart';
import '../../../../constant/colors.dart';
import '../../../../constant/links.dart';
import '../../../../constant/style.dart';
import '../../../views/widgets/elevated_btn.dart';
import '../../../views/widgets/mycircular.dart';
import '../registration_captain_controller.dart';

class RegisterCaptain extends StatelessWidget {
  RegisterCaptain({super.key});

  @override
  Widget build(BuildContext context) {
    final controller = Get.put(RegisterCaptainController());
    // String text = '';
    controller.driveInit();
    // final inspectionDate =
    //     controller.responseIdCardDriverEgyptBack['inspection_date'].toString();
    // final year = int.parse(inspectionDate.split('-')[0]);
    // final inspectionDateTime = DateTime(year, 12, 31);

    return MyScaffold(
        title: 'Documents check'.tr,
        action: GetBuilder<RegisterCaptainController>(builder: (controller) {
          return IconButton(
            onPressed: () {
              controller.isLoading = false;
              controller.update();
            },
            icon: const Icon(Icons.refresh),
          );
        }),
        body: [
          GetBuilder<RegisterCaptainController>(builder: (controller) {
            return controller.isLoading
                ? const MyCircularProgressIndicator()
                : Padding(
                    padding: const EdgeInsets.all(8.0),
                    child: Column(
                      children: [
                        (controller.responseIdCardDriverEgyptBack.isNotEmpty &&
                                controller.responseIdCardDriverEgyptFront
                                    .isNotEmpty &&
                                controller.responseIdEgyptFront.isNotEmpty &&
                                controller.responseIdEgyptBack.isNotEmpty &&
                                controller
                                    .responseIdEgyptDriverLicense.isNotEmpty
                            // &&
                            //     controller
                            //         .responseCriminalRecordEgypt.isNotEmpty
                            )
                            ? MyElevatedButton(
                                title: 'Next'.tr,
                                onPressed: () {
                                  controller.addDriverAndCarEgypt();
                                })
                            : const SizedBox(),
                        Row(
                          children: [
                            handleInsert(controller),
                            MyElevatedButton(
                                kolor: controller.isEgypt
                                    ? AppColor.greenColor
                                    : AppColor.redColor,
                                title: controller.isEgypt
                                    ? 'For Egypt'.tr
                                    : 'Non Egypt'.tr,
                                onPressed: () {
                                  controller.changeNationality();
                                })
                          ],
                        ),
                        SizedBox(
                          height: Get.height * .7,
                          child: ListView(
                            children: [
                              egyptDriverLicense(),
                              egyptCarLicenceFront(),
                              egyptCarLicenceBack(),
                              controller.isEgypt
                                  ? egyptDriverIDFront()
                                  : nonEgyptDriverIDFront(),
                              controller.isEgypt
                                  ? egyptDriverIDBack()
                                  : nonEgyptDriverIDBack(),
                              // egyptCriminalRecord(),
                            ],
                          ),
                        ),
                      ],
                    ),
                  );
          }),
        ],
        isleading: true);
  }

  // TextButton handleInsert(RegisterCaptainController controller) {
  //   return TextButton(
  //     onPressed: () {
  //       Get.to(MyScaffold(title: 'title', isleading: true, body: [
  //         Column(
  //           children: [
  //             SizedBox(
  //               height: Get.height * .8,
  //               child: Form(
  //                 child: ListView(
  //                   children: [
  //                     TextFormField(
  //                       initialValue:
  //                           controller.responseIdEgyptDriverLicense != null
  //                               ? controller
  //                                   .responseIdEgyptDriverLicense['firstName']
  //                                   ?.toString()
  //                               : controller.firstName.value,
  //                       decoration:
  //                           const InputDecoration(labelText: 'First Name'),
  //                       onChanged: (value) =>
  //                           controller.firstName.value = value,
  //                     ),
  //                     TextFormField(
  //                       initialValue:
  //                           controller.responseIdEgyptDriverLicense != null
  //                               ? controller
  //                                   .responseIdEgyptDriverLicense['lastName']
  //                                   ?.toString()
  //                               : controller.lastName.value,
  //                       decoration:
  //                           const InputDecoration(labelText: 'Last Name'),
  //                       onChanged: (value) => controller.lastName.value = value,
  //                     ),
  //                     TextFormField(
  //                       initialValue: controller.responseIdEgyptBack != null
  //                           ? controller.responseIdEgyptBack['gender']
  //                               ?.toString()
  //                           : controller.gender.value,
  //                       decoration: const InputDecoration(labelText: 'Gender'),
  //                       onChanged: (value) => controller.gender.value = value,
  //                     ),
  //                     TextFormField(
  //                       initialValue: controller.responseIdEgyptDriverLicense !=
  //                               null
  //                           ? controller
  //                               .responseIdEgyptDriverLicense['license_type']
  //                               ?.toString()
  //                           : controller.licenseType.value,
  //                       decoration:
  //                           const InputDecoration(labelText: 'License Type'),
  //                       onChanged: (value) =>
  //                           controller.licenseType.value = value,
  //                     ),
  //                     TextFormField(
  //                       initialValue: controller.responseIdEgyptDriverLicense !=
  //                               null
  //                           ? controller
  //                               .responseIdEgyptDriverLicense['national_number']
  //                               ?.toString()
  //                           : controller.nationalNumber.value,
  //                       decoration:
  //                           const InputDecoration(labelText: 'National Number'),
  //                       onChanged: (value) =>
  //                           controller.nationalNumber.value = value,
  //                     ),
  //                     TextFormField(
  //                       initialValue:
  //                           controller.responseIdEgyptDriverLicense != null
  //                               ? controller
  //                                   .responseIdEgyptDriverLicense['name_arabic']
  //                                   ?.toString()
  //                               : controller.nameArabic.value,
  //                       decoration:
  //                           const InputDecoration(labelText: 'Name in Arabic'),
  //                       onChanged: (value) =>
  //                           controller.nameArabic.value = value,
  //                     ),
  //                     TextFormField(
  //                       initialValue: controller.responseIdEgyptDriverLicense !=
  //                               null
  //                           ? controller
  //                               .responseIdEgyptDriverLicense['name_english']
  //                               ?.toString()
  //                           : controller.nameEnglish.value,
  //                       decoration:
  //                           const InputDecoration(labelText: 'Name in English'),
  //                       onChanged: (value) =>
  //                           controller.nameEnglish.value = value,
  //                     ),
  //                     TextFormField(
  //                       initialValue:
  //                           controller.responseIdEgyptDriverLicense != null
  //                               ? controller
  //                                   .responseIdEgyptDriverLicense['issue_date']
  //                                   ?.toString()
  //                               : controller.issueDate.value,
  //                       decoration:
  //                           const InputDecoration(labelText: 'Issue Date'),
  //                       onChanged: (value) =>
  //                           controller.issueDate.value = value,
  //                     ),
  //                     TextFormField(
  //                       initialValue:
  //                           controller.responseIdEgyptDriverLicense != null
  //                               ? controller
  //                                   .responseIdEgyptDriverLicense['expiry_date']
  //                                   ?.toString()
  //                               : controller.expirationDate.value,
  //                       decoration:
  //                           const InputDecoration(labelText: 'Expiry Date'),
  //                       onChanged: (value) =>
  //                           controller.expiryDate.value = value,
  //                     ),
  //                     TextFormField(
  //                       initialValue: controller.responseIdEgyptFront != null
  //                           ? controller.responseIdEgyptDriverLicense[
  //                                   'license_categories'] is List
  //                               ? controller.responseIdEgyptDriverLicense[
  //                                       'license_categories']
  //                                   .join(', ')
  //                               : controller.responseIdEgyptDriverLicense[
  //                                           'license_categories']
  //                                       ?.toString() ??
  //                                   'Not specified'
  //                           : controller.licenseCategories.value,
  //                       decoration: const InputDecoration(
  //                           labelText: 'License Categories'),
  //                       onChanged: (value) =>
  //                           controller.licenseCategories.value = value,
  //                     ),
  //                     TextFormField(
  //                       initialValue: controller.responseIdEgyptFront != null
  //                           ? controller.responseIdEgyptFront['address']
  //                               ?.toString()
  //                           : controller.fuel.value,
  //                       decoration: const InputDecoration(labelText: 'Address'),
  //                       onChanged: (value) => controller.address.value = value,
  //                     ),
  //                     TextFormField(
  //                       initialValue: controller.responseIdEgyptFront != null
  //                           ? controller.responseIdEgyptFront['card_id']
  //                               ?.toString()
  //                           : controller.cardId.value,
  //                       decoration: const InputDecoration(labelText: 'Card ID'),
  //                       onChanged: (value) => controller.cardId.value = value,
  //                     ),
  //                     TextFormField(
  //                       initialValue: controller.responseIdEgyptBack != null
  //                           ? controller.responseIdEgyptBack['occupation']
  //                               ?.toString()
  //                           : controller.education.value,
  //                       decoration:
  //                           const InputDecoration(labelText: 'Occupation'),
  //                       onChanged: (value) =>
  //                           controller.occupation.value = value,
  //                     ),
  //                     TextFormField(
  //                       initialValue: controller.responseIdEgyptBack != null
  //                           ? controller.responseIdEgyptBack['occupation']
  //                               ?.toString()
  //                           : controller.occupation.value,
  //                       decoration:
  //                           const InputDecoration(labelText: 'Education'),
  //                       onChanged: (value) =>
  //                           controller.education.value = value,
  //                     ),
  //                     TextFormField(
  //                       initialValue: controller.responseIdEgyptBack != null
  //                           ? controller.responseIdEgyptBack['issue_date']
  //                               ?.toString()
  //                           : controller.issueDate.value,
  //                       decoration: const InputDecoration(
  //                           labelText: 'License Issue Date'),
  //                       onChanged: (value) =>
  //                           controller.licenseIssueDate.value = value,
  //                     ),
  //                     TextFormField(
  //                       initialValue: controller.responseIdEgyptBack != null
  //                           ? controller.responseIdEgyptBack['religion']
  //                               ?.toString()
  //                           : controller.religion.value,
  //                       decoration:
  //                           const InputDecoration(labelText: 'Religion'),
  //                       onChanged: (value) => controller.religion.value = value,
  //                     ),
  //                     TextFormField(
  //                       initialValue: controller.responseIdEgyptBack != null
  //                           ? controller.responseIdEgyptBack['maritalStatus']
  //                               ?.toString()
  //                           : controller.maritalStatus.value,
  //                       decoration:
  //                           const InputDecoration(labelText: 'Marital Status'),
  //                       onChanged: (value) =>
  //                           controller.maritalStatus.value = value,
  //                     ),
  //                     TextFormField(
  //                       initialValue: controller.responseIdEgyptDriverLicense !=
  //                               null
  //                           ? controller.responseIdEgyptDriverLicense['address']
  //                               ?.toString()
  //                           : controller.address.value,
  //                       decoration: const InputDecoration(labelText: 'Site'),
  //                       onChanged: (value) => controller.site.value = value,
  //                     ),
  //                     TextFormField(
  //                       initialValue: controller.responseIdEgyptDriverLicense !=
  //                               null
  //                           ? controller
  //                               .responseIdEgyptDriverLicense['employmentType']
  //                               ?.toString()
  //                           : controller.employmentType.value,
  //                       decoration:
  //                           const InputDecoration(labelText: 'Employment Type'),
  //                       onChanged: (value) =>
  //                           controller.employmentType.value = value,
  //                     ),
  //                     const Divider(
  //                       thickness: 5,
  //                       height: 5,
  //                     ),
  //                     Text('Car Details'.tr),
  //                     const Divider(
  //                       thickness: 5,
  //                       height: 5,
  //                     ),
  //                     TextFormField(
  //                       initialValue: controller.vin.value.isEmpty
  //                           ? controller
  //                                   .responseIdCardDriverEgyptBack['chassis']
  //                                   ?.toString() ??
  //                               ''
  //                           : controller.vin.value,
  //                       decoration: const InputDecoration(labelText: 'VIN'),
  //                       onChanged: (value) => controller.vin.value = value,
  //                     ),
  //                     TextFormField(
  //                       initialValue: controller.vin.value.isEmpty
  //                           ? controller
  //                                   .responseIdCardDriverEgyptBack['car_plate']
  //                                   ?.toString() ??
  //                               ''
  //                           : controller.vin.value,
  //                       decoration:
  //                           const InputDecoration(labelText: 'car_plate'),
  //                       onChanged: (value) => controller.vin.value = value,
  //                     ),
  //                     TextFormField(
  //                       initialValue: controller.make.value.isEmpty
  //                           ? controller.responseIdCardDriverEgyptBack['make']
  //                                   ?.toString() ??
  //                               ''
  //                           : controller.make.value,
  //                       decoration: const InputDecoration(labelText: 'Make'),
  //                       onChanged: (value) => controller.make.value = value,
  //                     ),
  //                     TextFormField(
  //                       initialValue: controller.model.value.isEmpty
  //                           ? controller.responseIdCardDriverEgyptBack['model']
  //                                   ?.toString() ??
  //                               ''
  //                           : controller.model.value,
  //                       decoration: const InputDecoration(labelText: 'Model'),
  //                       onChanged: (value) => controller.model.value = value,
  //                     ),
  //                     TextFormField(
  //                       initialValue: controller.year.value.isEmpty
  //                           ? controller.responseIdCardDriverEgyptBack['year']
  //                                   ?.toString() ??
  //                               ''
  //                           : controller.year.value,
  //                       decoration: const InputDecoration(labelText: 'Year'),
  //                       onChanged: (value) => controller.year.value = value,
  //                     ),
  //                     TextFormField(
  //                       initialValue: controller.displacement.value.isEmpty
  //                           ? controller.responseIdCardDriverEgyptBack['engine']
  //                                   ?.toString() ??
  //                               ''
  //                           : controller.displacement.value,
  //                       decoration:
  //                           const InputDecoration(labelText: 'Displacement'),
  //                       onChanged: (value) =>
  //                           controller.displacement.value = value,
  //                     ),
  //                     TextFormField(
  //                       initialValue: controller.fuel.value.isEmpty
  //                           ? controller.responseIdCardDriverEgyptBack['fuel']
  //                                   ?.toString() ??
  //                               ''
  //                           : controller.fuel.value,
  //                       decoration: const InputDecoration(labelText: 'Fuel'),
  //                       onChanged: (value) => controller.fuel.value = value,
  //                     ),
  //                     DropdownButtonFormField<String>(
  //                       decoration: InputDecoration(
  //                         labelText: 'Color'.tr, // Localized label
  //                       ),
  //                       value: controller.color.value.isEmpty
  //                           ? null
  //                           : controller.color.value,
  //                       items: [
  //                         {'red'.tr: '#FF0000'},
  //                         {'green'.tr: '#008000'},
  //                         {'blue'.tr: '#0000FF'},
  //                         {'black'.tr: '#000000'},
  //                         {'white'.tr: '#FFFFFF'},
  //                         {'yellow'.tr: '#FFFF00'},
  //                         {'purple'.tr: '#800080'},
  //                         {'orange'.tr: '#FFA500'},
  //                         {'pink'.tr: '#FFC0CB'},
  //                         {'brown'.tr: '#A52A2A'},
  //                         {'gray'.tr: '#808080'},
  //                         {'cyan'.tr: '#00FFFF'},
  //                         {'magenta'.tr: '#FF00FF'},
  //                         {'lime'.tr: '#00FF00'},
  //                         {'indigo'.tr: '#4B0082'},
  //                         {'violet'.tr: '#EE82EE'},
  //                         {'gold'.tr: '#FFD700'},
  //                         {'silver'.tr: '#C0C0C0'},
  //                         {'teal'.tr: '#008080'},
  //                         {'navy'.tr: '#000080'},
  //                       ].map((colorMap) {
  //                         String colorName = colorMap.keys.first;
  //                         String colorValue = colorMap.values.first;
  //                         return DropdownMenuItem<String>(
  //                           value: colorValue,
  //                           child: Text(colorName),
  //                         );
  //                       }).toList(),
  //                       onChanged: (value) {
  //                         controller.color.value = value ?? '';
  //                         controller.colorHex.value = value ?? '';
  //                       },
  //                     ),
  //                     TextFormField(
  //                       initialValue: controller.owner.value.isNotEmpty
  //                           ? controller.responseIdCardDriverEgyptFront['owner']
  //                               ?.toString()
  //                           : controller.owner.value,
  //                       decoration: const InputDecoration(labelText: 'Owner'),
  //                       onChanged: (value) => controller.owner.value = value,
  //                     ),
  //                     TextFormField(
  //                       initialValue: controller.expirationDate.value.isNotEmpty
  //                           ? controller.responseIdCardDriverEgyptFront[
  //                                   'expiration_date']
  //                               ?.toString()
  //                           : controller.owner.value,
  //                       decoration:
  //                           const InputDecoration(labelText: 'expiration_date'),
  //                       onChanged: (value) =>
  //                           controller.expirationDate.value = value,
  //                     ),
  //                     TextFormField(
  //                       initialValue: controller.addressCar.isNotEmpty
  //                           ? controller
  //                               .responseIdCardDriverEgyptFront['address']
  //                               ?.toString()
  //                           : controller.addressCar.value,
  //                       decoration: const InputDecoration(labelText: 'Address'),
  //                       onChanged: (value) =>
  //                           controller.addressCar.value = value,
  //                     ),
  //                     // TextFormField(
  //                     //   initialValue: inspectionDateTime
  //                     //       .toString(),
  //                     //   decoration:
  //                     //       const InputDecoration(
  //                     //           labelText:
  //                     //               'Registration Date'),
  //                     //   onChanged: (value) => controller
  //                     //       .registrationDate
  //                     //       .value = value,
  //                     // ),
  //                     const SizedBox(height: 20),
  //                   ],
  //                 ),
  //               ),
  //             ),
  //             MyElevatedButton(
  //               title: 'Upload'.tr,
  //               onPressed: () async {
  //                 await controller.addDriverEgyptHanding();
  //                 await controller.addRegistrationCarEgyptHandling();
  //                 // await controller
  //                 //     .getDriverNotCompleteRegistration();
  //               },
  //               kolor: AppColor.greenColor,
  //             ),
  //           ],
  //         ),
  //       ]));
  //       // Get.defaultDialog(
  //       //     barrierDismissible: false,
  //       //     title: 'Insert all fields'.tr,
  //       //     content: SizedBox(
  //       //       height: 400,
  //       //       width: 300,
  //       //       child: Form(
  //       //         child: ListView(
  //       //           children: [
  //       //             TextFormField(
  //       //               initialValue:
  //       //                   controller.responseIdEgyptDriverLicense !=
  //       //                           null
  //       //                       ? controller
  //       //                           .responseIdEgyptDriverLicense[
  //       //                               'firstName']
  //       //                           ?.toString()
  //       //                       : controller.firstName.value,
  //       //               decoration: const InputDecoration(
  //       //                   labelText: 'First Name'),
  //       //               onChanged: (value) => controller
  //       //                   .firstName.value = value,
  //       //             ),
  //       //             TextFormField(
  //       //               initialValue:
  //       //                   controller.responseIdEgyptDriverLicense !=
  //       //                           null
  //       //                       ? controller
  //       //                           .responseIdEgyptDriverLicense[
  //       //                               'lastName']
  //       //                           ?.toString()
  //       //                       : controller.lastName.value,
  //       //               decoration: const InputDecoration(
  //       //                   labelText: 'Last Name'),
  //       //               onChanged: (value) =>
  //       //                   controller.lastName.value = value,
  //       //             ),
  //       //             TextFormField(
  //       //               initialValue: controller
  //       //                           .responseIdEgyptBack !=
  //       //                       null
  //       //                   ? controller
  //       //                       .responseIdEgyptBack['gender']
  //       //                       ?.toString()
  //       //                   : controller.gender.value,
  //       //               decoration: const InputDecoration(
  //       //                   labelText: 'Gender'),
  //       //               onChanged: (value) =>
  //       //                   controller.gender.value = value,
  //       //             ),
  //       //             TextFormField(
  //       //               initialValue:
  //       //                   controller.responseIdEgyptDriverLicense !=
  //       //                           null
  //       //                       ? controller
  //       //                           .responseIdEgyptDriverLicense[
  //       //                               'license_type']
  //       //                           ?.toString()
  //       //                       : controller
  //       //                           .licenseType.value,
  //       //               decoration: const InputDecoration(
  //       //                   labelText: 'License Type'),
  //       //               onChanged: (value) => controller
  //       //                   .licenseType.value = value,
  //       //             ),
  //       //             TextFormField(
  //       //               initialValue:
  //       //                   controller.responseIdEgyptDriverLicense !=
  //       //                           null
  //       //                       ? controller
  //       //                           .responseIdEgyptDriverLicense[
  //       //                               'national_number']
  //       //                           ?.toString()
  //       //                       : controller
  //       //                           .nationalNumber.value,
  //       //               decoration: const InputDecoration(
  //       //                   labelText: 'National Number'),
  //       //               onChanged: (value) => controller
  //       //                   .nationalNumber.value = value,
  //       //             ),
  //       //             TextFormField(
  //       //               initialValue:
  //       //                   controller.responseIdEgyptDriverLicense !=
  //       //                           null
  //       //                       ? controller
  //       //                           .responseIdEgyptDriverLicense[
  //       //                               'name_arabic']
  //       //                           ?.toString()
  //       //                       : controller.nameArabic.value,
  //       //               decoration: const InputDecoration(
  //       //                   labelText: 'Name in Arabic'),
  //       //               onChanged: (value) => controller
  //       //                   .nameArabic.value = value,
  //       //             ),
  //       //             TextFormField(
  //       //               initialValue:
  //       //                   controller.responseIdEgyptDriverLicense !=
  //       //                           null
  //       //                       ? controller
  //       //                           .responseIdEgyptDriverLicense[
  //       //                               'name_english']
  //       //                           ?.toString()
  //       //                       : controller
  //       //                           .nameEnglish.value,
  //       //               decoration: const InputDecoration(
  //       //                   labelText: 'Name in English'),
  //       //               onChanged: (value) => controller
  //       //                   .nameEnglish.value = value,
  //       //             ),
  //       //             TextFormField(
  //       //               initialValue:
  //       //                   controller.responseIdEgyptDriverLicense !=
  //       //                           null
  //       //                       ? controller
  //       //                           .responseIdEgyptDriverLicense[
  //       //                               'issue_date']
  //       //                           ?.toString()
  //       //                       : controller.issueDate.value,
  //       //               decoration: const InputDecoration(
  //       //                   labelText: 'Issue Date'),
  //       //               onChanged: (value) => controller
  //       //                   .issueDate.value = value,
  //       //             ),
  //       //             TextFormField(
  //       //               initialValue:
  //       //                   controller.responseIdEgyptDriverLicense !=
  //       //                           null
  //       //                       ? controller
  //       //                           .responseIdEgyptDriverLicense[
  //       //                               'expiry_date']
  //       //                           ?.toString()
  //       //                       : controller
  //       //                           .expirationDate.value,
  //       //               decoration: const InputDecoration(
  //       //                   labelText: 'Expiry Date'),
  //       //               onChanged: (value) => controller
  //       //                   .expiryDate.value = value,
  //       //             ),
  //       //             TextFormField(
  //       //               initialValue: controller
  //       //                           .responseIdEgyptFront !=
  //       //                       null
  //       //                   ? controller.responseIdEgyptDriverLicense[
  //       //                               'license_categories']
  //       //                           is List
  //       //                       ? controller
  //       //                           .responseIdEgyptDriverLicense[
  //       //                               'license_categories']
  //       //                           .join(', ')
  //       //                       : controller
  //       //                               .responseIdEgyptDriverLicense[
  //       //                                   'license_categories']
  //       //                               ?.toString() ??
  //       //                           'Not specified'
  //       //                   : controller
  //       //                       .licenseCategories.value,
  //       //               decoration: const InputDecoration(
  //       //                   labelText: 'License Categories'),
  //       //               onChanged: (value) => controller
  //       //                   .licenseCategories.value = value,
  //       //             ),
  //       //             TextFormField(
  //       //               initialValue: controller
  //       //                           .responseIdEgyptFront !=
  //       //                       null
  //       //                   ? controller.responseIdEgyptFront[
  //       //                           'address']
  //       //                       ?.toString()
  //       //                   : controller.fuel.value,
  //       //               decoration: const InputDecoration(
  //       //                   labelText: 'Address'),
  //       //               onChanged: (value) =>
  //       //                   controller.address.value = value,
  //       //             ),
  //       //             TextFormField(
  //       //               initialValue: controller
  //       //                           .responseIdEgyptFront !=
  //       //                       null
  //       //                   ? controller.responseIdEgyptFront[
  //       //                           'card_id']
  //       //                       ?.toString()
  //       //                   : controller.cardId.value,
  //       //               decoration: const InputDecoration(
  //       //                   labelText: 'Card ID'),
  //       //               onChanged: (value) =>
  //       //                   controller.cardId.value = value,
  //       //             ),
  //       //             TextFormField(
  //       //               initialValue: controller
  //       //                           .responseIdEgyptBack !=
  //       //                       null
  //       //                   ? controller.responseIdEgyptBack[
  //       //                           'occupation']
  //       //                       ?.toString()
  //       //                   : controller.education.value,
  //       //               decoration: const InputDecoration(
  //       //                   labelText: 'Occupation'),
  //       //               onChanged: (value) => controller
  //       //                   .occupation.value = value,
  //       //             ),
  //       //             TextFormField(
  //       //               initialValue: controller
  //       //                           .responseIdEgyptBack !=
  //       //                       null
  //       //                   ? controller.responseIdEgyptBack[
  //       //                           'occupation']
  //       //                       ?.toString()
  //       //                   : controller.occupation.value,
  //       //               decoration: const InputDecoration(
  //       //                   labelText: 'Education'),
  //       //               onChanged: (value) => controller
  //       //                   .education.value = value,
  //       //             ),
  //       //             TextFormField(
  //       //               initialValue: controller
  //       //                           .responseIdEgyptBack !=
  //       //                       null
  //       //                   ? controller.responseIdEgyptBack[
  //       //                           'issue_date']
  //       //                       ?.toString()
  //       //                   : controller.issueDate.value,
  //       //               decoration: const InputDecoration(
  //       //                   labelText: 'License Issue Date'),
  //       //               onChanged: (value) => controller
  //       //                   .licenseIssueDate.value = value,
  //       //             ),
  //       //             TextFormField(
  //       //               initialValue: controller
  //       //                           .responseIdEgyptBack !=
  //       //                       null
  //       //                   ? controller.responseIdEgyptBack[
  //       //                           'religion']
  //       //                       ?.toString()
  //       //                   : controller.religion.value,
  //       //               decoration: const InputDecoration(
  //       //                   labelText: 'Religion'),
  //       //               onChanged: (value) =>
  //       //                   controller.religion.value = value,
  //       //             ),
  //       //             TextFormField(
  //       //               initialValue: controller
  //       //                           .responseIdEgyptBack !=
  //       //                       null
  //       //                   ? controller.responseIdEgyptBack[
  //       //                           'maritalStatus']
  //       //                       ?.toString()
  //       //                   : controller.maritalStatus.value,
  //       //               decoration: const InputDecoration(
  //       //                   labelText: 'Marital Status'),
  //       //               onChanged: (value) => controller
  //       //                   .maritalStatus.value = value,
  //       //             ),
  //       //             TextFormField(
  //       //               initialValue:
  //       //                   controller.responseIdEgyptDriverLicense !=
  //       //                           null
  //       //                       ? controller
  //       //                           .responseIdEgyptDriverLicense[
  //       //                               'address']
  //       //                           ?.toString()
  //       //                       : controller.address.value,
  //       //               decoration: const InputDecoration(
  //       //                   labelText: 'Site'),
  //       //               onChanged: (value) =>
  //       //                   controller.site.value = value,
  //       //             ),
  //       //             TextFormField(
  //       //               initialValue:
  //       //                   controller.responseIdEgyptDriverLicense !=
  //       //                           null
  //       //                       ? controller
  //       //                           .responseIdEgyptDriverLicense[
  //       //                               'employmentType']
  //       //                           ?.toString()
  //       //                       : controller
  //       //                           .employmentType.value,
  //       //               decoration: const InputDecoration(
  //       //                   labelText: 'Employment Type'),
  //       //               onChanged: (value) => controller
  //       //                   .employmentType.value = value,
  //       //             ),
  //       //             const Divider(
  //       //               thickness: 5,
  //       //               height: 5,
  //       //             ),
  //       //             Text('Car Details'.tr),
  //       //             const Divider(
  //       //               thickness: 5,
  //       //               height: 5,
  //       //             ),
  //       //             TextFormField(
  //       //               initialValue:
  //       //                   controller.responseIdCardDriverEgyptBack !=
  //       //                           null
  //       //                       ? controller
  //       //                           .responseIdCardDriverEgyptBack[
  //       //                               'chassis']
  //       //                           ?.toString()
  //       //                       : controller.vin.value,
  //       //               decoration: const InputDecoration(
  //       //                   labelText: 'VIN'),
  //       //               onChanged: (value) =>
  //       //                   controller.vin.value = value,
  //       //             ),
  //       //             TextFormField(
  //       //               initialValue:
  //       //                   controller.responseIdCardDriverEgyptBack !=
  //       //                           null
  //       //                       ? controller
  //       //                           .responseIdCardDriverEgyptBack[
  //       //                               'make']
  //       //                           ?.toString()
  //       //                       : controller.make.value,
  //       //               decoration: const InputDecoration(
  //       //                   labelText: 'Make'),
  //       //               onChanged: (value) =>
  //       //                   controller.make.value = value,
  //       //             ),
  //       //             TextFormField(
  //       //               initialValue:
  //       //                   controller.responseIdCardDriverEgyptBack !=
  //       //                           null
  //       //                       ? controller
  //       //                           .responseIdCardDriverEgyptBack[
  //       //                               'model']
  //       //                           ?.toString()
  //       //                       : controller.model.value,
  //       //               decoration: const InputDecoration(
  //       //                   labelText: 'Model'),
  //       //               onChanged: (value) =>
  //       //                   controller.model.value = value,
  //       //             ),
  //       //             TextFormField(
  //       //               initialValue:
  //       //                   controller.responseIdCardDriverEgyptBack !=
  //       //                           null
  //       //                       ? controller
  //       //                           .responseIdCardDriverEgyptBack[
  //       //                               'year']
  //       //                           ?.toString()
  //       //                       : controller.year.value,
  //       //               decoration: const InputDecoration(
  //       //                   labelText: 'Year'),
  //       //               onChanged: (value) =>
  //       //                   controller.year.value = value,
  //       //             ),
  //       //             TextFormField(
  //       //               initialValue:
  //       //                   controller.responseIdCardDriverEgyptBack !=
  //       //                           null
  //       //                       ? controller
  //       //                           .responseIdCardDriverEgyptBack[
  //       //                               'engine']
  //       //                           ?.toString()
  //       //                       : controller
  //       //                           .displacement.value,
  //       //               decoration: const InputDecoration(
  //       //                   labelText: 'Displacement'),
  //       //               onChanged: (value) => controller
  //       //                   .displacement.value = value,
  //       //             ),
  //       //             TextFormField(
  //       //               initialValue:
  //       //                   controller.responseIdCardDriverEgyptBack !=
  //       //                           null
  //       //                       ? controller
  //       //                           .responseIdCardDriverEgyptBack[
  //       //                               'fuel']
  //       //                           ?.toString()
  //       //                       : controller.fuel.value,
  //       //               decoration: const InputDecoration(
  //       //                   labelText: 'Fuel'),
  //       //               onChanged: (value) =>
  //       //                   controller.fuel.value = value,
  //       //             ),
  //       //             DropdownButtonFormField<String>(
  //       //               decoration: InputDecoration(
  //       //                 labelText:
  //       //                     'Color'.tr, // Localized label
  //       //               ),
  //       //               value: controller.color.value.isEmpty
  //       //                   ? null
  //       //                   : controller.color.value,
  //       //               items: [
  //       //                 {'red'.tr: '#FF0000'},
  //       //                 {'green'.tr: '#008000'},
  //       //                 {'blue'.tr: '#0000FF'},
  //       //                 {'black'.tr: '#000000'},
  //       //                 {'white'.tr: '#FFFFFF'},
  //       //                 {'yellow'.tr: '#FFFF00'},
  //       //                 {'purple'.tr: '#800080'},
  //       //                 {'orange'.tr: '#FFA500'},
  //       //                 {'pink'.tr: '#FFC0CB'},
  //       //                 {'brown'.tr: '#A52A2A'},
  //       //                 {'gray'.tr: '#808080'},
  //       //                 {'cyan'.tr: '#00FFFF'},
  //       //                 {'magenta'.tr: '#FF00FF'},
  //       //                 {'lime'.tr: '#00FF00'},
  //       //                 {'indigo'.tr: '#4B0082'},
  //       //                 {'violet'.tr: '#EE82EE'},
  //       //                 {'gold'.tr: '#FFD700'},
  //       //                 {'silver'.tr: '#C0C0C0'},
  //       //                 {'teal'.tr: '#008080'},
  //       //                 {'navy'.tr: '#000080'},
  //       //               ].map((colorMap) {
  //       //                 String colorName =
  //       //                     colorMap.keys.first;
  //       //                 String colorValue =
  //       //                     colorMap.values.first;
  //       //                 return DropdownMenuItem<String>(
  //       //                   value: colorValue,
  //       //                   child: Text(colorName),
  //       //                 );
  //       //               }).toList(),
  //       //               onChanged: (value) {
  //       //                 controller.color.value =
  //       //                     value ?? '';
  //       //                 controller.colorHex.value =
  //       //                     value ?? '';
  //       //               },
  //       //             ),
  //       //             TextFormField(
  //       //               initialValue:
  //       //                   controller.responseIdCardDriverEgyptFront !=
  //       //                           null
  //       //                       ? controller
  //       //                           .responseIdCardDriverEgyptFront[
  //       //                               'owner']
  //       //                           ?.toString()
  //       //                       : controller.owner.value,
  //       //               decoration: const InputDecoration(
  //       //                   labelText: 'Owner'),
  //       //               onChanged: (value) =>
  //       //                   controller.owner.value = value,
  //       //             ),
  //       //             TextFormField(
  //       //               initialValue:
  //       //                   controller.responseIdCardDriverEgyptFront !=
  //       //                           null
  //       //                       ? controller
  //       //                           .responseIdCardDriverEgyptFront[
  //       //                               'address']
  //       //                           ?.toString()
  //       //                       : controller.addressCar.value,
  //       //               decoration: const InputDecoration(
  //       //                   labelText: 'Address'),
  //       //               onChanged: (value) => controller
  //       //                   .addressCar.value = value,
  //       //             ),
  //       //             TextFormField(
  //       //               initialValue:
  //       //                   inspectionDateTime.toString(),
  //       //               decoration: const InputDecoration(
  //       //                   labelText: 'Registration Date'),
  //       //               onChanged: (value) => controller
  //       //                   .registrationDate.value = value,
  //       //             ),
  //       //             const SizedBox(height: 20),
  //       //           ],
  //       //         ),
  //       //       ),
  //       //     ),
  //       //     confirm: MyElevatedButton(
  //       //       title: 'Upload'.tr,
  //       //       onPressed: () async {
  //       //         await controller.addDriverEgyptHanding();
  //       //         await controller
  //       //             .addRegistrationCarEgyptHandling();
  //       //         await controller
  //       //             .getDriverNotCompleteRegistration();
  //       //         Get.back();
  //       //       },
  //       //       kolor: AppColor.greenColor,
  //       //     ),
  //       //     cancel: MyElevatedButton(
  //       //         kolor: AppColor.redColor,
  //       //         title: 'Cancel'.tr,
  //       //         onPressed: () {
  //       //           Get.back();
  //       //         }));
  //     },
  //     child: Text(
  //       "hand inserting".tr,
  //     ),
  //   );
  // }

  TextButton handleInsert(RegisterCaptainController controller) {
    final now = DateTime.now();
    final formattedDate = DateFormat('yyyy-MM-dd').format(now);
    return TextButton(
      onPressed: () {
        Get.to(MyScaffold(
          title: 'title',
          isleading: true,
          body: [
            Column(
              children: [
                Expanded(
                  // Use Expanded to make the Form scrollable if needed
                  child: Form(
                    child: ListView(
                      padding: const EdgeInsets.all(16.0),
                      children: [
                        //------------------------ Personal info ---------------------------
                        Text('Personal Information'.tr,
                            style: TextStyle(
                                fontSize: 18, fontWeight: FontWeight.bold)),
                        const Divider(thickness: 1),
                        TextFormField(
                          initialValue: controller
                                  .responseIdEgyptDriverLicense?['firstName']
                                  ?.toString() ??
                              controller.firstName.value,
                          decoration:
                              const InputDecoration(labelText: 'First Name'),
                          onChanged: (value) =>
                              controller.firstName.value = value,
                        ),
                        TextFormField(
                          initialValue: controller
                                  .responseIdEgyptDriverLicense?['lastName']
                                  ?.toString() ??
                              controller.lastName.value,
                          decoration:
                              const InputDecoration(labelText: 'Last Name'),
                          onChanged: (value) =>
                              controller.lastName.value = value,
                        ),
                        TextFormField(
                          initialValue: controller
                                  .responseIdEgyptBack?['gender']
                                  ?.toString() ??
                              controller.gender.value,
                          decoration:
                              const InputDecoration(labelText: 'Gender'),
                          onChanged: (value) => controller.gender.value = value,
                        ),
                        TextFormField(
                          initialValue: controller
                                  .responseIdEgyptDriverLicense?['license_type']
                                  ?.toString() ??
                              controller.licenseType.value,
                          decoration:
                              const InputDecoration(labelText: 'License Type'),
                          onChanged: (value) =>
                              controller.licenseType.value = value,
                        ),
                        TextFormField(
                          initialValue: controller
                                  .responseIdEgyptDriverLicense?[
                                      'national_number']
                                  ?.toString() ??
                              controller.nationalNumber.value,
                          decoration: const InputDecoration(
                              labelText: 'National Number'),
                          onChanged: (value) =>
                              controller.nationalNumber.value = value,
                        ),
                        TextFormField(
                          initialValue: controller
                                  .responseIdEgyptDriverLicense?['name_arabic']
                                  ?.toString() ??
                              controller.nameArabic.value,
                          decoration: const InputDecoration(
                              labelText: 'Name in Arabic'),
                          onChanged: (value) =>
                              controller.nameArabic.value = value,
                        ),
                        TextFormField(
                          initialValue: controller
                                  .responseIdEgyptDriverLicense?['name_english']
                                  ?.toString() ??
                              controller.nameEnglish.value,
                          decoration: const InputDecoration(
                              labelText: 'Name in English'),
                          onChanged: (value) =>
                              controller.nameEnglish.value = value,
                        ),
                        TextFormField(
                          initialValue: controller
                                  .responseIdEgyptDriverLicense?['issue_date']
                                  ?.toString() ??
                              controller.issueDate.value,
                          decoration:
                              const InputDecoration(labelText: 'Issue Date'),
                          onChanged: (value) =>
                              controller.issueDate.value = value,
                        ),
                        TextFormField(
                          initialValue: controller
                                  .responseIdEgyptDriverLicense?['expiry_date']
                                  ?.toString() ??
                              controller.expirationDate.value,
                          decoration:
                              const InputDecoration(labelText: 'Expiry Date'),
                          onChanged: (value) =>
                              controller.expiryDate.value = value,
                        ),
                        TextFormField(
                          initialValue:
                              controller.responseIdEgyptDriverLicense?[
                                      'license_categories'] is List
                                  ? (controller.responseIdEgyptDriverLicense?[
                                          'license_categories'] as List)
                                      .join(', ')
                                  : controller.responseIdEgyptDriverLicense?[
                                              'license_categories']
                                          ?.toString() ??
                                      controller.licenseCategories.value,
                          decoration: const InputDecoration(
                              labelText: 'License Categories'),
                          onChanged: (value) =>
                              controller.licenseCategories.value = value,
                        ),
                        TextFormField(
                          initialValue: controller
                                  .responseIdEgyptFront?['address']
                                  ?.toString() ??
                              controller.address.value,
                          decoration:
                              const InputDecoration(labelText: 'Address'),
                          onChanged: (value) =>
                              controller.address.value = value,
                        ),
                        TextFormField(
                          initialValue: controller
                                  .responseIdEgyptFront?['card_id']
                                  ?.toString() ??
                              controller.cardId.value,
                          decoration:
                              const InputDecoration(labelText: 'Card ID'),
                          onChanged: (value) => controller.cardId.value = value,
                        ),
                        TextFormField(
                          initialValue: controller
                                  .responseIdEgyptBack?['occupation']
                                  ?.toString() ??
                              controller.occupation.value,
                          decoration:
                              const InputDecoration(labelText: 'Occupation'),
                          onChanged: (value) =>
                              controller.occupation.value = value,
                        ),
                        TextFormField(
                          initialValue: controller
                                  .responseIdEgyptBack?['occupation']
                                  ?.toString() ??
                              controller.education.value,
                          decoration:
                              const InputDecoration(labelText: 'Education'),
                          onChanged: (value) =>
                              controller.education.value = value,
                        ),
                        TextFormField(
                          initialValue: controller
                                  .responseIdEgyptBack?['issue_date']
                                  ?.toString() ??
                              controller.licenseIssueDate.value,
                          decoration: const InputDecoration(
                              labelText: 'License Issue Date'),
                          onChanged: (value) =>
                              controller.licenseIssueDate.value = value,
                        ),
                        TextFormField(
                          initialValue: controller
                                  .responseIdEgyptBack?['religion']
                                  ?.toString() ??
                              controller.religion.value,
                          decoration:
                              const InputDecoration(labelText: 'Religion'),
                          onChanged: (value) =>
                              controller.religion.value = value,
                        ),
                        TextFormField(
                          initialValue: controller
                                  .responseIdEgyptBack?['maritalStatus']
                                  ?.toString() ??
                              controller.maritalStatus.value,
                          decoration: const InputDecoration(
                              labelText: 'Marital Status'),
                          onChanged: (value) =>
                              controller.maritalStatus.value = value,
                        ),
                        TextFormField(
                          initialValue: controller
                                  .responseIdEgyptDriverLicense?['address']
                                  ?.toString() ??
                              controller.site.value,
                          decoration: const InputDecoration(labelText: 'Site'),
                          onChanged: (value) => controller.site.value = value,
                        ),
                        TextFormField(
                          initialValue: controller
                                  .responseIdEgyptDriverLicense?[
                                      'employmentType']
                                  ?.toString() ??
                              controller.employmentType.value,
                          decoration: const InputDecoration(
                              labelText: 'Employment Type'),
                          onChanged: (value) =>
                              controller.employmentType.value = value,
                        ),

                        //------------------------ Car Details ---------------------------

                        const SizedBox(height: 20),
                        Text('Car Details'.tr,
                            style: TextStyle(
                                fontSize: 18, fontWeight: FontWeight.bold)),
                        const Divider(thickness: 1),

                        TextFormField(
                          initialValue: controller.vin.value.isEmpty
                              ? controller
                                      .responseIdCardDriverEgyptBack['chassis']
                                      ?.toString() ??
                                  ''
                              : controller.vin.value,
                          decoration: const InputDecoration(labelText: 'VIN'),
                          onChanged: (value) => controller.vin.value = value,
                        ),
                        TextFormField(
                          initialValue: controller.vin.value.isEmpty
                              ? controller.responseIdCardDriverEgyptBack[
                                          'car_plate']
                                      ?.toString() ??
                                  ''
                              : controller.vin.value,
                          decoration:
                              const InputDecoration(labelText: 'Car Plate'),
                          onChanged: (value) => controller.carPlate.value =
                              value, // changed to carPlate
                        ),
                        TextFormField(
                          initialValue: controller.make.value.isEmpty
                              ? controller.responseIdCardDriverEgyptBack['make']
                                      ?.toString() ??
                                  ''
                              : controller.make.value,
                          decoration: const InputDecoration(labelText: 'Make'),
                          onChanged: (value) => controller.make.value = value,
                        ),
                        TextFormField(
                          initialValue: controller.model.value.isEmpty
                              ? controller
                                      .responseIdCardDriverEgyptBack['model']
                                      ?.toString() ??
                                  ''
                              : controller.model.value,
                          decoration: const InputDecoration(labelText: 'Model'),
                          onChanged: (value) => controller.model.value = value,
                        ),
                        TextFormField(
                          initialValue: controller.year.value.isEmpty
                              ? controller.responseIdCardDriverEgyptBack['year']
                                      ?.toString() ??
                                  ''
                              : controller.year.value,
                          decoration: const InputDecoration(labelText: 'Year'),
                          onChanged: (value) => controller.year.value = value,
                        ),
                        TextFormField(
                          initialValue: controller.displacement.value.isEmpty
                              ? controller
                                      .responseIdCardDriverEgyptBack['engine']
                                      ?.toString() ??
                                  ''
                              : controller.displacement.value,
                          decoration:
                              const InputDecoration(labelText: 'Displacement'),
                          onChanged: (value) =>
                              controller.displacement.value = value,
                        ),
                        TextFormField(
                          initialValue: controller.fuel.value.isEmpty
                              ? controller.responseIdCardDriverEgyptBack['fuel']
                                      ?.toString() ??
                                  ''
                              : controller.fuel.value,
                          decoration: const InputDecoration(labelText: 'Fuel'),
                          onChanged: (value) => controller.fuel.value = value,
                        ),
                        DropdownButtonFormField<String>(
                          decoration: InputDecoration(labelText: 'Color'.tr),
                          value: controller.color.value.isEmpty
                              ? null
                              : controller.color.value,
                          items: [
                            {'red'.tr: '#FF0000'},
                            {'green'.tr: '#008000'},
                            {'blue'.tr: '#0000FF'},
                            {'black'.tr: '#000000'},
                            {'white'.tr: '#FFFFFF'},
                            {'yellow'.tr: '#FFFF00'},
                            {'purple'.tr: '#800080'},
                            {'orange'.tr: '#FFA500'},
                            {'pink'.tr: '#FFC0CB'},
                            {'brown'.tr: '#A52A2A'},
                            {'gray'.tr: '#808080'},
                            {'cyan'.tr: '#00FFFF'},
                            {'magenta'.tr: '#FF00FF'},
                            {'lime'.tr: '#00FF00'},
                            {'indigo'.tr: '#4B0082'},
                            {'violet'.tr: '#EE82EE'},
                            {'gold'.tr: '#FFD700'},
                            {'silver'.tr: '#C0C0C0'},
                            {'teal'.tr: '#008080'},
                            {'navy'.tr: '#000080'},
                          ].map((colorMap) {
                            String colorName = colorMap.keys.first;
                            String colorValue = colorMap.values.first;
                            return DropdownMenuItem<String>(
                              value: colorValue,
                              child: Text(colorName),
                            );
                          }).toList(),
                          onChanged: (value) {
                            controller.color.value = value ?? '';
                            controller.colorHex.value = value ?? '';
                          },
                        ),
                        TextFormField(
                          initialValue: controller.owner.value.isEmpty
                              ? controller
                                      .responseIdCardDriverEgyptFront['owner']
                                      ?.toString() ??
                                  ''
                              : controller.owner.value,
                          decoration: const InputDecoration(labelText: 'Owner'),
                          onChanged: (value) => controller.owner.value = value,
                        ),
                        TextFormField(
                          initialValue: controller.expirationDate.value.isEmpty
                              ? controller.responseIdCardDriverEgyptFront[
                                          'expiration_date']
                                      ?.toString() ??
                                  ''
                              : controller.expirationDate.value,
                          decoration: const InputDecoration(
                              labelText: 'Expiration Date'),
                          onChanged: (value) =>
                              controller.expirationDate.value = value,
                        ),
                        TextFormField(
                          initialValue: controller.addressCar.isEmpty
                              ? controller
                                      .responseIdCardDriverEgyptFront['address']
                                      ?.toString() ??
                                  ''
                              : controller.addressCar.value,
                          decoration:
                              const InputDecoration(labelText: 'Address'),
                          onChanged: (value) =>
                              controller.addressCar.value = value,
                        ),
                        TextFormField(
                          initialValue:
                              controller.registrationDate.value.isEmpty
                                  ? formattedDate
                                  : controller.registrationDate.value,
                          decoration: const InputDecoration(
                              labelText: 'Registration Date'),
                          onChanged: (value) =>
                              controller.registrationDate.value = value,
                        ),

                        const SizedBox(height: 20),
                      ],
                    ),
                  ),
                ),
                MyElevatedButton(
                  title: 'Upload'.tr,
                  onPressed: () async {
                    await controller.addDriverEgyptHanding();
                    if (controller.responseIdCardDriverEgyptBack != null) {
                      await controller.addRegistrationCarEgyptHandling();
                    }

                    Get.back();
                    //   await controller.getDriverNotCompleteRegistration();
                  },
                  kolor: AppColor.greenColor,
                ),
              ],
            ),
          ],
        ));
      },
      child: Text("Hand Inserting".tr),
    );
  }

  GetBuilder<RegisterCaptainController> egyptDriverLicense() {
    return GetBuilder<RegisterCaptainController>(
      builder: (ai) {
        if (ai.responseIdEgyptDriverLicense.isNotEmpty) {
          final expiryDate = ai.responseIdEgyptDriverLicense['expiry_date'];

          // Check if the expiry date is before today
          final today = DateTime.now();

          // Try parsing the expiry date. If it fails, set it to null.
          final expiryDateTime = DateTime.tryParse(expiryDate);
          final isExpired =
              expiryDateTime != null && expiryDateTime.isBefore(today);

          return Card(
            elevation: 4.0,
            shape: RoundedRectangleBorder(
              borderRadius: BorderRadius.circular(16.0),
            ),
            child: Padding(
              padding: const EdgeInsets.all(16.0),
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
                      Text('Driver\'s License'.tr, style: AppStyle.headTitle2),
                      IconButton(
                        onPressed: () async {
                          await ai.allMethodForAI("""

Here’s the updated version of your prompt with the necessary changes:

{
"license_type": "",
"national_number": "",
"name_arabic": "",
"name_english": "",
"firstName": "",
"lastName": "",
"address": "",
"issue_date": "",
"expiry_date": "",
"employmentType": "",
"license_categories": []
} • Only include fields that are present in the input text. Use null for any missing values.
• Format dates as YYYY-MM-DD.
• For the national_number, ensure it is provided in Latin numerals and consists of exactly 14 digits. Remove any non-numeric characters or incorrect length and format it properly.
• For the name, split the name into first and last names based on the structure provided.

The response should adhere to the specified format and include only the requested fields.
""", 'driver_license', ai.driverId); //egypt
                        },
                        icon: const Icon(Icons.refresh),
                      ),
                    ],
                  ),
                  const SizedBox(height: 8.0),
                  const Divider(color: AppColor.accentColor),
                  const SizedBox(height: 8.0),
                  Text(
                    '${'License Type'.tr}: ${ai.responseIdEgyptDriverLicense['license_type']}',
                    style: AppStyle.title,
                  ),
                  const SizedBox(height: 8.0),
                  Text(
                    '${'National Number'.tr}: ${ai.responseIdEgyptDriverLicense['national_number']}',
                    style: AppStyle.title.copyWith(
                        color: ai.responseIdEgyptDriverLicense[
                                    'national_number'] ==
                                ai.responseIdEgyptBack['nationalID']
                            ? AppColor.greenColor
                            : AppColor.redColor),
                  ),
                  const SizedBox(height: 8.0),
                  Text(
                    '${'Name (Arabic)'.tr}: ${ai.responseIdEgyptDriverLicense['name_arabic']}',
                  ),
                  const SizedBox(height: 8.0),
                  Text(
                    '${'Name (English)'.tr}: ${ai.responseIdEgyptDriverLicense['name_english']}',
                  ),
                  const SizedBox(height: 8.0),
                  Text(
                    '${'Address'.tr}: ${ai.responseIdEgyptDriverLicense['address']}',
                  ),
                  const SizedBox(height: 8.0),
                  Text(
                    '${'Issue Date'.tr}: ${ai.responseIdEgyptDriverLicense['issue_date']}',
                  ),
                  const SizedBox(height: 8.0),
                  Text(
                    '${'Expiry Date'.tr}: ${ai.responseIdEgyptDriverLicense['expiry_date']}',
                    style: AppStyle.title.copyWith(
                      color:
                          !isExpired ? AppColor.greenColor : AppColor.redColor,
                    ),
                  ),
                  const SizedBox(height: 8.0),
                  Text(
                    '${'License Categories'.tr}: ${ai.responseIdEgyptDriverLicense['license_categories']}',
                  ),
                ],
              ),
            ),
          );
        }
        return Card(
          child: InkWell(
            onTap: () async {
              await ai.allMethodForAI("""

Here’s the updated version of your prompt with the necessary changes:

{
"license_type": "",
"national_number": "",
"name_arabic": "",
"name_english": "",
"firstName": "",
"lastName": "",
"address": "",
"issue_date": "",
"expiry_date": "",
"employmentType": "",
"license_categories": []
} • Only include fields that are present in the input text. Use null for any missing values.
• Format dates as YYYY-MM-DD.
• For the national_number, ensure it is provided in Latin numerals and consists of exactly 14 digits. Remove any non-numeric characters or incorrect length and format it properly.
• For the name, split the name into first and last names based on the structure provided.

The response should adhere to the specified format and include only the requested fields.
""", 'driver_license', ai.driverId); //egypt
            },
            child: Column(
              children: [
                Image.network(
                  '${AppLink.server}/card_image/driver_license-${ai.driverId}.jpg',
                  height: Get.height * .25,
                  width: double.maxFinite,
                  fit: BoxFit.fitHeight,
                  errorBuilder: (BuildContext context, Object exception,
                      StackTrace? stackTrace) {
                    return Text("Not found any image".tr);
                  },
                ),
                Text(
                  'Capture an Image of Your Driver License'.tr,
                  style: AppStyle.title,
                ),
              ],
            ),
          ),
        );
      },
    );
  }

  GetBuilder<RegisterCaptainController> egyptDriverIDBack() {
    return GetBuilder<RegisterCaptainController>(
      builder: (ai) {
        if (ai.responseIdEgyptBack.isNotEmpty) {
          final taxExpiryDate = ai.responseIdEgyptBack['expirationDate'];

          // Check if the tax expiry date is before today
          final today = DateTime.now();

          // Try parsing the tax expiry date. If it fails, set it to null.
          final taxExpiryDateTime = DateTime.tryParse(taxExpiryDate);
          final isExpired =
              taxExpiryDateTime != null && taxExpiryDateTime.isBefore(today);

          return Card(
            elevation: 4.0,
            shape: RoundedRectangleBorder(
              borderRadius: BorderRadius.circular(16.0),
            ),
            child: Padding(
              padding: const EdgeInsets.all(16.0),
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
                      Text('ID Documents Back'.tr, style: AppStyle.headTitle2),
                      IconButton(
                        onPressed: () async {
                          await ai.allMethodForAI("""
                         Given the following Arabic text values:


Please create a JSON object with the following fields:


nationalID: Use exactly 14 digits, converting from Arabic numerals to Latin numerals (0-9).
issueDate: Format as YYYY-MM-DD using Latin numerals, setting the date to the last day of the provided month.
occupation: Translate and format consistently (e.g., all lowercase).
gender: Use the values "Male" or "Female" without translation.
country: Set to "جمهورية مصر العربية".
religion: Translate and format consistently (e.g., all lowercase).
maritalStatus: Translate and format consistently (e.g., all lowercase).
fullNameMarital: If maritalStatus is "أعزب", set this to "none". Otherwise, leave it as "none".
expirationDate: Format as YYYY-MM-DD using Latin numerals.
Important notes:


Ensure all date fields use Latin (Western) numerals (0-9) instead of Arabic numerals.
For the nationalID, use exactly 14 digits from the provided Arabic numeral string, converting to Latin numerals.
For issueDate, use the last day of the month since only year and month are provided.
Include the country field as "جمهورية مصر العربية".
Format all string values consistently (e.g., all lowercase or proper case)
                            """, 'id_back', ai.driverId); //egypt
                        },
                        icon: const Icon(Icons.refresh),
                      ),
                    ],
                  ),
                  const SizedBox(height: 8.0),
                  const Divider(color: AppColor.accentColor),
                  const SizedBox(height: 8.0),
                  // Assuming these keys exist in ai.responseIdEgyptFront
                  Text(
                    '${'National ID'.tr}: ${ai.responseIdEgyptBack['nationalID']}',
                    style: AppStyle.title.copyWith(
                        color: ai.responseIdEgyptDriverLicense[
                                    'national_number'] ==
                                ai.responseIdEgyptBack['nationalID']
                            ? AppColor.greenColor
                            : AppColor.redColor),
                  ),

                  const SizedBox(height: 8.0),
                  Text(
                    '${'Occupation'.tr}: ${ai.responseIdEgyptBack['occupation']}', // Assuming 'occupation' exists
                  ),
                  const SizedBox(height: 8.0),
                  Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
                      Text(
                        '${'Issue Date'.tr}: ${ai.responseIdEgyptBack['issueDate']}', // Assuming 'issueDate' exists
                      ),
                      Text(
                        '${'Gender'.tr}: ${ai.responseIdEgyptBack['gender']}', // Assuming 'gender' exists
                      ),
                    ],
                  ),
                  const SizedBox(height: 8.0),
                  // Row(
                  //   mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  //   children: [
                  //     Text(
                  //       '${'Religion'.tr}: ${ai.responseIdEgyptBack['religion']}', // Assuming 'religion' exists
                  //     ),
                  //     Text(
                  //       '${'Marital Status'.tr}: ${ai.responseIdEgyptBack['maritalStatus']}', // Assuming 'maritalStatus' exists
                  //     ),
                  //   ],
                  // ),
                  // const SizedBox(height: 8.0),
                  // Text(
                  //   '${'Full Name (Marital)'.tr}: ${ai.responseIdEgyptBack['fullNameMaritial']}', // Assuming 'fullNameMaritial' exists
                  // ),
                  // const SizedBox(height: 8.0),
                  Text(
                    '${'Expiration Date'.tr}: ${ai.responseIdEgyptBack['expirationDate']}', // Assuming 'expirationDate' exists
                    style: AppStyle.title.copyWith(
                        color: !isExpired
                            ? AppColor.greenColor
                            : AppColor.redColor),
                  ),
                ],
              ),
            ),
          );
        }
        return Card(
          child: InkWell(
            onTap: () async {
              await ai.allMethodForAI('''
                 Given the following Arabic text values:


Please create a JSON object with the following fields:


nationalID: Use exactly 14 digits, converting from Arabic numerals to Latin numerals (0-9).
issueDate: Format as YYYY-MM-DD using Latin numerals, setting the date to the last day of the provided month.
occupation: Translate and format consistently (e.g., all lowercase).
gender: Use the values "Male" or "Female" without translation.
country: Set to "جمهورية مصر العربية".
religion: Translate and format consistently (e.g., all lowercase).
maritalStatus: Translate and format consistently (e.g., all lowercase).
fullNameMarital: If maritalStatus is "أعزب", set this to "none". Otherwise, leave it as "none".
expirationDate: Format as YYYY-MM-DD using Latin numerals.
Important notes:


Ensure all date fields use Latin (Western) numerals (0-9) instead of Arabic numerals.
For the nationalID, use exactly 14 digits from the provided Arabic numeral string, converting to Latin numerals.
For issueDate, use the last day of the month since only year and month are provided.
Include the country field as "جمهورية مصر العربية".
Format all string values consistently (e.g., all lowercase or proper case)
                  ''', 'id_back', ai.driverId); //egypt
            },
            child: Column(
              children: [
                Image.network(
                  '${AppLink.server}/card_image/id_back-${ai.driverId}.jpg',
                  height: Get.height * .25,
                  width: double.maxFinite,
                  fit: BoxFit.fitHeight,
                  errorBuilder: (BuildContext context, Object exception,
                      StackTrace? stackTrace) {
                    return Text("Not found any image".tr);
                  },
                ),
                Text(
                  'Capture an Image of Your ID Document Back'.tr,
                  style: AppStyle.title,
                ),
              ],
            ),
          ),
        );
      },
    );
  }

  GetBuilder<RegisterCaptainController> nonEgyptDriverIDBack() {
    return GetBuilder<RegisterCaptainController>(
      builder: (ai) {
        if (ai.responseIdEgyptBack.isNotEmpty) {
          final taxExpiryDate = ai.responseIdEgyptBack['expirationDate'];

          // Check if the tax expiry date is before today
          final today = DateTime.now();

          // Try parsing the tax expiry date. If it fails, set it to null.
          final taxExpiryDateTime = DateTime.tryParse(taxExpiryDate);
          final isExpired =
              taxExpiryDateTime != null && taxExpiryDateTime.isBefore(today);

          return Card(
            elevation: 4.0,
            shape: RoundedRectangleBorder(
              borderRadius: BorderRadius.circular(16.0),
            ),
            child: Padding(
              padding: const EdgeInsets.all(16.0),
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
                      Text('ID Documents Back'.tr, style: AppStyle.headTitle2),
                      IconButton(
                        onPressed: () async {
                          await ai.allMethodForAI("""
                       Given an Egyptian residence card data:

1. From the Arabic text sections:
   - Extract residency type after "نوع الإقامة:"
   - Extract work status (غير مصرح بالعمل or مصرح بالعمل)

2. From the issue date line:
   - Parse date after "IssueDate:" in YYYY-MM-DD format

3. From MRZ line 2 (e.g., "9205200M2706258SYR"):
   First part (before 'M'):
   - If digit before 'M' is 2: year = "19" + first 2 digits
   - If digit before 'M' is 3: year = "20" + first 2 digits
   - Month = next 2 digits
   - Day = last 2 digits
   
   After 'M':
   - Year = "20" + first 2 digits
   - Month = next 2 digits
   - Day = last 2 digits
   
   Country code:
   - Last 3 characters convert to Arabic country name

Format as JSON with fields:
- issueDate
- birthDate
- residencyType
- workStatus
- country (in Arabic)
- residencyExpirationDate
                            """, 'id_back', ai.driverId); //egypt
                        },
                        icon: const Icon(Icons.refresh),
                      ),
                    ],
                  ),
                  const SizedBox(height: 8.0),
                  const Divider(color: AppColor.accentColor),
                  const SizedBox(height: 8.0),
                  // Assuming these keys exist in ai.responseIdEgyptFront
                  Text(
                    '${'National ID'.tr}: ${ai.responseIdEgyptBack['nationalID']}',
                    style: AppStyle.title.copyWith(
                        color: ai.responseIdEgyptDriverLicense[
                                    'national_number'] ==
                                ai.responseIdEgyptBack['nationalID']
                            ? AppColor.greenColor
                            : AppColor.redColor),
                  ),

                  const SizedBox(height: 8.0),
                  Text(
                    '${'Occupation'.tr}: ${ai.responseIdEgyptBack['occupation']}', // Assuming 'occupation' exists
                  ),
                  const SizedBox(height: 8.0),
                  Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
                      Text(
                        '${'Issue Date'.tr}: ${ai.responseIdEgyptBack['issueDate']}', // Assuming 'issueDate' exists
                      ),
                      Text(
                        '${'Gender'.tr}: ${ai.responseIdEgyptBack['gender']}', // Assuming 'gender' exists
                      ),
                    ],
                  ),
                  const SizedBox(height: 8.0),
                  // Row(
                  //   mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  //   children: [
                  //     Text(
                  //       '${'Religion'.tr}: ${ai.responseIdEgyptBack['religion']}', // Assuming 'religion' exists
                  //     ),
                  //     Text(
                  //       '${'Marital Status'.tr}: ${ai.responseIdEgyptBack['maritalStatus']}', // Assuming 'maritalStatus' exists
                  //     ),
                  //   ],
                  // ),
                  // const SizedBox(height: 8.0),
                  // Text(
                  //   '${'Full Name (Marital)'.tr}: ${ai.responseIdEgyptBack['fullNameMaritial']}', // Assuming 'fullNameMaritial' exists
                  // ),
                  // const SizedBox(height: 8.0),
                  Text(
                    '${'Expiration Date'.tr}: ${ai.responseIdEgyptBack['expirationDate']}', // Assuming 'expirationDate' exists
                    style: AppStyle.title.copyWith(
                        color: !isExpired
                            ? AppColor.greenColor
                            : AppColor.redColor),
                  ),
                ],
              ),
            ),
          );
        }
        return Card(
          child: InkWell(
            onTap: () async {
              await ai.allMethodForAI('''
                Given an Egyptian residence card data:

1. From the Arabic text sections:
   - Extract residency type after "نوع الإقامة:"
   - Extract work status (غير مصرح بالعمل or مصرح بالعمل)

2. From the issue date line:
   - Parse date after "IssueDate:" in YYYY-MM-DD format

3. From MRZ line 2 (e.g., "9205200M2706258SYR"):
   First part (before 'M'):
   - If digit before 'M' is 2: year = "19" + first 2 digits
   - If digit before 'M' is 3: year = "20" + first 2 digits
   - Month = next 2 digits
   - Day = last 2 digits
   
   After 'M':
   - Year = "20" + first 2 digits
   - Month = next 2 digits
   - Day = last 2 digits
   
   Country code:
   - Last 3 characters convert to Arabic country name

Format as JSON with fields:
- issueDate
- birthDate
- residencyType
- workStatus
- country (in Arabic)
- residencyExpirationDate ''', 'id_back', ai.driverId); //egypt
            },
            child: Column(
              children: [
                Image.network(
                  '${AppLink.server}/card_image/id_back-${ai.driverId}.jpg',
                  height: Get.height * .25,
                  width: double.maxFinite,
                  fit: BoxFit.fitHeight,
                  errorBuilder: (BuildContext context, Object exception,
                      StackTrace? stackTrace) {
                    return Text("Not found any image".tr);
                  },
                ),
                Text(
                  'Capture an Image of Your ID Document Back'.tr,
                  style: AppStyle.title,
                ),
              ],
            ),
          ),
        );
      },
    );
  }

  GetBuilder<RegisterCaptainController> nonEgyptDriverIDFront() {
    return GetBuilder<RegisterCaptainController>(
      builder: (ai) {
        if (ai.responseNonIdCardFront.isNotEmpty) {
          return Card(
            elevation: 4.0,
            shape: RoundedRectangleBorder(
              borderRadius: BorderRadius.circular(16.0),
            ),
            child: Padding(
              padding: const EdgeInsets.all(16.0),
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
                      Text('Non-Egyptian ID Front'.tr, style: AppStyle.title),
                      IconButton(
                        onPressed: () async {
                          await ai.allMethodForAI("""
                              Given the following Arabic text values:

1. The full name.
2. The passport number, preceded by "جواز رقم".
3. The country, located immediately after the passport number.
4. The birth date, formatted in Arabic numerals as YYYY/MM/DD.
5. The gender, written in Arabic ("ذكر" for "Male" and "أنثى" for "Female").
6. The address, located after "العنوان".
7. The card ID, found at the bottom right of the document.

Create a structured JSON object with the following fields:
- full_name: The full name, directly as written in Arabic.
- passport_no: Extract the passport number.
- country: Extract the country following the passport number.
- birthdate: Format the birth date as YYYY-MM-DD using Western numerals (0-9).
- gender: Convert "ذكر" to "Male" and "أنثى" to "Female".
- address: Extract the full address as written.
- card_id: Extract the ID from the bottom right.

Ensure the JSON is properly formatted and all values are accurately mapped.
{
  "first_name": "", // The word next to "بطاقة تحقيق الشخصية" (National Identification Card)
  "full_name": "", // The full name on the next line after the first name
  "address": "", // The complete address spanning the next two lines
  "national_number": "", // The National ID number before the last line (convert Arabic numerals to Latin)
  "card_id": "", // The card ID in English on the last line
  "dob": "" // Year of birth only, in Latin numerals (YYYY format)
}

Important notes:
1. For 'first_name', extract the word immediately following "بطاقة تحقيق الشخصية".
2. 'full_name' should be the complete name found on the line after the first name.
3. 'address' should combine information from two consecutive lines.
4. Convert the 'national_number' from Arabic numerals to Latin numerals (0-9).
5. 'card_id' should be extracted as-is from the last line (it's already in English).
6. For 'dob', include only the year of birth in YYYY format using Latin numerals.
7. If any information is missing, leave the field as an empty string.
                              """, AppLink.uploadEgypt, 'non_id_front');
                        },
                        icon: const Icon(Icons.refresh),
                      ),
                    ],
                  ),
                  const SizedBox(height: 8.0),
                  const Divider(color: AppColor.accentColor),
                  const SizedBox(height: 8.0),
                  Text(
                    '${'Full Name'.tr}: ${ai.responseNonIdCardFront['full_name']}',
                    style: AppStyle.title,
                  ),
                  const SizedBox(height: 8.0),
                  Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
                      Text(
                        '${'Passport No'.tr}: ${ai.responseNonIdCardFront['passport_no']}',
                      ),
                      Text(
                        '${'Card ID'.tr}: ${ai.responseNonIdCardFront['card_id']}',
                      ),
                    ],
                  ),
                  const SizedBox(height: 8.0),
                  Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
                      Text(
                        '${'Country'.tr}: ${ai.responseNonIdCardFront['country']}',
                      ),
                      Text(
                        '${'Gender'.tr}: ${ai.responseNonIdCardFront['gender']}',
                      ),
                    ],
                  ),
                  const SizedBox(height: 8.0),
                  Text(
                    '${'Birth Date'.tr}: ${ai.responseNonIdCardFront['birthdate']}',
                  ),
                  const SizedBox(height: 8.0),
                  Text(
                    '${'Address'.tr}: ${ai.responseNonIdCardFront['address']}',
                  ),
                ],
              ),
            ),
          );
        }
        return Card(
          child: InkWell(
            onTap: () async {
              await ai.allMethodForAI("""
Given the following Arabic text values:

1. The full name.
2. The passport number, preceded by "جواز رقم".
3. The country, located immediately after the passport number.
4. The birth date, formatted in Arabic numerals as YYYY/MM/DD.
5. The gender, written in Arabic ("ذكر" for "Male" and "أنثى" for "Female").
6. The address, located after "العنوان".
7. The card ID, found at the bottom right of the document.

Create a structured JSON object with the following fields:
- full_name: The full name, directly as written in Arabic.
- passport_no: Extract the passport number.
- country: Extract the country following the passport number.
- birthdate: Format the birth date as YYYY-MM-DD using Western numerals (0-9).
- gender: Convert "ذكر" to "Male" and "أنثى" to "Female".
- address: Extract the full address as written.
- card_id: Extract the ID from the bottom right.

Ensure the JSON is properly formatted and all values are accurately mapped.
{
  "first_name": "", // The word next to "بطاقة تحقيق الشخصية" (National Identification Card)
  "full_name": "", // The full name on the next line after the first name
  "address": "", // The complete address spanning the next two lines
  "national_number": "", // The National ID number before the last line (convert Arabic numerals to Latin)
  "card_id": "", // The card ID in English on the last line
  "dob": "" // Year of birth only, in Latin numerals (YYYY format)
}

Important notes:
1. For 'first_name', extract the word immediately following "بطاقة تحقيق الشخصية".
2. 'full_name' should be the complete name found on the line after the first name.
3. 'address' should combine information from two consecutive lines.
4. Convert the 'national_number' from Arabic numerals to Latin numerals (0-9).
5. 'card_id' should be extracted as-is from the last line (it's already in English).
6. For 'dob', include only the year of birth in YYYY format using Latin numerals.
7. If any information is missing, leave the field as an empty string.
""", AppLink.uploadEgypt, 'non_id_front');
            },
            child: Column(
              children: [
                Image.asset(
                  'assets/images/7.jpeg',
                  height: Get.height * .25,
                  width: double.maxFinite,
                  fit: BoxFit.fitHeight,
                ),
                Text(
                  'Capture Image of Non-Egyptian ID Front'.tr,
                  style: AppStyle.title,
                ),
              ],
            ),
          ),
        );
      },
    );
  }

  GetBuilder<RegisterCaptainController> egyptDriverIDFront() {
    return GetBuilder<RegisterCaptainController>(
      builder: (ai) {
        if (ai.responseIdEgyptFront.isNotEmpty) {
          return Card(
            elevation: 4.0,
            shape: RoundedRectangleBorder(
              borderRadius: BorderRadius.circular(16.0),
            ),
            child: Padding(
              padding: const EdgeInsets.all(16.0),
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
                      Text('ID Documents Front'.tr, style: AppStyle.headTitle2),
                      IconButton(
                        onPressed: () async {
                          await ai.allMethodForAI('''
                              Write a JSON object from the following information extracted from the provided Arabic text:

{
  "first_name": "", // The word next to "بطاقة تحقيق الشخصية" (National Identification Card)
  "full_name": "", // The full name on the next line after the first name
  "address": "", // The complete address spanning the next two lines
  "national_number": "", // The National ID number before the last line (convert Arabic numerals to Latin)
  "card_id": "", // The card ID in English on the last line
  "dob": "" // Year of birth only, in Latin numerals (YYYY format)
}

Important notes:
1. For 'first_name', extract the word immediately following "بطاقة تحقيق الشخصية".
2. 'full_name' should be the complete name found on the line after the first name.
3. 'address' should combine information from two consecutive lines.
4. Convert the 'national_number' from Arabic numerals to Latin numerals (0-9).
5. 'card_id' should be extracted as-is from the last line (it's already in English).
6. For 'dob', include only the year of birth in YYYY format using Latin numerals.
7. If any information is missing, leave the field as an empty string.
                              ''', 'id_front', ai.driverId); //egypt
                        },
                        icon: const Icon(Icons.refresh),
                      ),
                    ],
                  ),
                  const SizedBox(height: 8.0),
                  const Divider(color: AppColor.accentColor),
                  const SizedBox(height: 8.0),
                  // Removed Make, Model, etc. as they are not available

                  Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
                      Text(
                        '${'First Name'.tr}: ${ai.responseIdEgyptFront['first_name']}',
                      ),
                      Text(
                        '${'CardID'.tr}: ${ai.responseIdEgyptFront['card_id']}',
                      ),
                    ],
                  ),
                  const SizedBox(height: 8.0),
                  Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
                      Text(
                        '${'Full Name'.tr}: ${ai.responseIdEgyptFront['full_name']}',
                      ),
                      Text(
                        '${'DOB'.tr}: ${ai.responseIdEgyptFront['dob']}',
                      ),
                    ],
                  ),
                  const SizedBox(height: 8.0),
                  Text(
                    '${'Address'.tr}: ${ai.responseIdEgyptFront['address']}',
                  ),
                  const SizedBox(height: 8.0),
                  // Text(
                  //   '${'National Number'.tr}: ${ai.responseIdEgyptFront['national_number']}',
                  // ),
                  // const SizedBox(height: 8.0),

                  // Removed Inspection Date as it's not available
                ],
              ),
            ),
          );
        }
        return Card(
          child: InkWell(
            onTap: () async {
              await ai.allMethodForAI(""""
                 Write a JSON object from the following information extracted from the provided Arabic text:

{
  "first_name": "", // The word next to "بطاقة تحقيق الشخصية" (National Identification Card)
  "full_name": "", // The full name on the next line after the first name
  "address": "", // The complete address spanning the next two lines
  "national_number": "", // The National ID number before the last line (convert Arabic numerals to Latin)
  "card_id": "", // The card ID in English on the last line
  "dob": "" // Year of birth only, in Latin numerals (YYYY format)
}

Important notes:
1. For 'first_name', extract the word immediately following "بطاقة تحقيق الشخصية".
2. 'full_name' should be the complete name found on the line after the first name.
3. 'address' should combine information from two consecutive lines.
4. Convert the 'national_number' from Arabic numerals to Latin numerals (0-9).
5. 'card_id' should be extracted as-is from the last line (it's already in English).
6. For 'dob', include only the year of birth in YYYY format using Latin numerals.
7. If any information is missing, leave the field as an empty string.
                 """, 'id_front', ai.driverId); //egypt
            },
            child: Column(
              children: [
                Image.network(
                  //api.sefer.live/sefer/card_image/id_front-110822466514385876961.jpg
                  '${AppLink.server}/card_image/id_front-${ai.driverId}.jpg',
                  height: Get.height * .25,
                  width: double.maxFinite,
                  fit: BoxFit.fitHeight,
                  errorBuilder: (BuildContext context, Object exception,
                      StackTrace? stackTrace) {
                    return Text("Not found any image".tr);
                  },
                ),
                Text(
                  'Capture an Image of Your ID Document front'.tr,
                  style: AppStyle.title,
                ),
              ],
            ),
          ),
        );
      },
    );
  }

  GetBuilder<RegisterCaptainController> egyptCarLicenceFront() {
    return GetBuilder<RegisterCaptainController>(
      builder: (ai) {
        if (ai.responseIdCardDriverEgyptFront.isNotEmpty) {
          // No need to access ai.responseIdCardDriverEgyptBack anymore
          final licenseExpiryDate = DateTime.parse(
              ai.responseIdCardDriverEgyptFront['LicenseExpirationDate']);

          // Check if license has expired
          final today = DateTime.now();
          final isLicenseExpired = licenseExpiryDate.isBefore(today);

          return Card(
            elevation: 4.0,
            shape: RoundedRectangleBorder(
              borderRadius: BorderRadius.circular(16.0),
            ),
            child: Padding(
              padding: const EdgeInsets.all(16.0),
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Row(
                    children: [
                      Text('Vehicle Details Front'.tr,
                          style: AppStyle.headTitle2),
                      IconButton(
                        onPressed: () async {
                          ai.allMethodForAI("""
                                   Extract the following details from the provided car license data and format them into a JSON object:


License Expiration Date
Car Plate
Owner
Address

Car License Data:


JSON Format:
{
"LicenseExpirationDate": "YYYY-MM-DD",
"car_plate": "[Car plate number]",//the car plate is  line next to line contain 'ادارة مرور' for bot numbers and letters in arabic with partition like| but you remove |
"owner": "[Owner's full name]",
"address": "[Address if available, otherwise 'Not provided']"
}

Important notes:
1. For the LicenseExpirationDate, ensure the date is in YYYY-MM-DD format using Latin numerals (0-9).
2. Replace all occurrences of '|' (pipe character) with a space in all fields.
3. If any information is missing, leave the corresponding field as an empty string.
4. Ensure all text is properly formatted and spaces are used correctly.

Please fill in the JSON object with the extracted information, following these guidelines.
""", 'car_front', ai.driverId);
                        },
                        icon: const Icon(Icons.refresh),
                      ),
                    ],
                  ),
                  const SizedBox(height: 8.0),
                  const Divider(color: AppColor.accentColor),
                  const SizedBox(height: 8.0),
                  // Removed Make, Model, etc. as they are not available

                  Text(
                    '${'Plate Number'.tr}: ${ai.responseIdCardDriverEgyptFront['car_plate']}',
                  ),
                  const SizedBox(height: 8.0),
                  Text(
                    '${'Owner Name'.tr}: ${ai.responseIdCardDriverEgyptFront['owner']}',
                  ),
                  const SizedBox(height: 8.0),
                  Text(
                    '${'Address'.tr}: ${ai.responseIdCardDriverEgyptFront['address']}',
                  ),
                  const SizedBox(height: 8.0),
                  Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
                      Text(
                        '${'License Expiry Date'.tr}: ${licenseExpiryDate.toString().substring(0, 10)}',
                        style: TextStyle(
                          color: isLicenseExpired ? Colors.red : Colors.green,
                        ),
                      ),
                      // Removed Fuel as it's not available
                    ],
                  ),
                  // Removed Inspection Date as it's not available
                ],
              ),
            ),
          );
        }
        return Card(
          child: InkWell(
            onTap: () async {
              ai.allMethodForAI("""
                            Extract the following details from the provided car license data and format them into a JSON object:


License Expiration Date
Car Plate
Owner
Address

Car License Data:


JSON Format:
{
"LicenseExpirationDate": "YYYY-MM-DD",
"car_plate": "[Car plate number]",//the car plate is  line next to line contain 'ادارة مرور' for bot numbers and letters in arabic with partition like| but you remove |
"owner": "[Owner's full name]",
"address": "[Address if available, otherwise 'Not provided']"
}

Important notes:
1. For the LicenseExpirationDate, ensure the date is in YYYY-MM-DD format using Latin numerals (0-9).
2. Replace all occurrences of '|' (pipe character) with a space in all fields.
3. If any information is missing, leave the corresponding field as an empty string.
4. Ensure all text is properly formatted and spaces are used correctly.

Please fill in the JSON object with the extracted information, following these guidelines.
""", 'car_front', ai.driverId);
            },
            child: Column(
              children: [
                Image.network(
                  '${AppLink.server}/card_image/car_front-${ai.driverId}.jpg',
                  height: Get.height * .25,
                  width: double.maxFinite,
                  fit: BoxFit.fitHeight,
                  errorBuilder: (BuildContext context, Object exception,
                      StackTrace? stackTrace) {
                    return Text("Not found any image".tr);
                  },
                ),
                Text(
                  'Capture an Image of Your car license front'.tr,
                  style: AppStyle.title,
                ),
              ],
            ),
          ),
        );
      },
    );
  }

  GetBuilder<RegisterCaptainController> egyptCarLicenceBack() {
    return GetBuilder<RegisterCaptainController>(
      builder: (ai) {
        if (ai.responseIdCardDriverEgyptBack.isNotEmpty) {
          // Get the tax expiry date from the response
          final taxExpiryDate = ai.responseIdCardDriverEgyptBack['tax_expiry'];
          // final displacement = ai.responseIdCardDriverEgyptBack['displacement'];
          // if (int.parse(displacement) < 1000) {}
          // Get the inspection date from the response
          final inspectionDate =
              ai.responseIdCardDriverEgyptBack['inspection_date'];
          final year = int.parse(inspectionDate.split('-')[0]);

// Set inspectionDateTime to December 31st of the given year
          final inspectionDateTime = DateTime(year, 12, 31);
          String carBackLicenseExpired =
              inspectionDateTime.toString().split(' ')[0];
// Get the current date
          final today = DateTime.now();

// Try parsing the tax expiry date. If it fails, set it to null.
          final taxExpiryDateTime = DateTime.tryParse(taxExpiryDate ?? '');
          final isExpired =
              taxExpiryDateTime != null && taxExpiryDateTime.isBefore(today);
// Check if the inspection date is before today
          bool isInspectionExpired = inspectionDateTime.isBefore(today);

          return Card(
            elevation: 4.0,
            shape: RoundedRectangleBorder(
              borderRadius: BorderRadius.circular(16.0),
            ),
            child: Padding(
              padding: const EdgeInsets.all(16.0),
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
                      Text('Vehicle Details Back'.tr,
                          style: AppStyle.headTitle2),
                      IconButton(
                        onPressed: () async {
                          ai.allMethodForAI("""
Analyze the extracted car license information and create a JSON object with the following keys:

{
  "make": "",
  "year": "",
  "chassis": "",
  "model": "",
  "engine": "",
  "displacement": "",
  "cylinders": "",
  "fuel": "",
  "color": "",
  "color_hex": "",
  "inspection_date": "",
  "assuranceNumber": "",
  "tax_expiry": ""
}

Important notes:
1. For dates (inspection_date and tax_expiry), use the format YYYY-MM-DD with Latin numerals (0-9).
2. Convert the color name to its corresponding hex color code for the 'color_hex' field.
3. Ensure all numeric values (year, displacement, cylinders) are in Latin numerals.
4. If any information is missing, leave the corresponding field as an empty string.
5. Do not include any explanatory text in the JSON fields, only the extracted values.
displacement in the line contain (سم٣ )
Please fill in the JSON object with the extracted information, following these guidelines.
""", 'car_back', ai.driverId);
                        },
                        icon: const Icon(Icons.refresh),
                      ),
                    ],
                  ),
                  const SizedBox(height: 8.0),
                  const Divider(color: AppColor.accentColor),
                  const SizedBox(height: 8.0),
                  Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
                      Text(
                          '${'Make'.tr}: ${ai.responseIdCardDriverEgyptBack['make']}'),
                      Text(
                          '${'Model'.tr}: ${ai.responseIdCardDriverEgyptBack['model']}'),
                    ],
                  ),
                  const SizedBox(height: 8.0),
                  Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
                      Text(
                          '${'Year'.tr}: ${ai.responseIdCardDriverEgyptBack['year']}'),
                      Text(
                          '${'Chassis'.tr}: ${ai.responseIdCardDriverEgyptBack['chassis']}'),
                    ],
                  ),
                  const SizedBox(height: 8.0),
                  Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
                      Text(
                          '${'Color'.tr}: ${ai.responseIdCardDriverEgyptBack['color']}'),
                      Text(
                          '${'Displacement'.tr}: ${ai.responseIdCardDriverEgyptBack['displacement']} cc'),
                    ],
                  ),
                  const SizedBox(height: 8.0),
                  Text(
                      '${'Fuel'.tr}: ${ai.responseIdCardDriverEgyptBack['fuel']}'),
                  const SizedBox(height: 8.0),
                  if (taxExpiryDateTime != null)
                    Text(
                      '${'Tax Expiry Date'.tr}: $taxExpiryDate',
                      style: TextStyle(
                        color: isExpired ? Colors.red : Colors.green,
                      ),
                    ),
                  const SizedBox(height: 8.0),
                  Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
                      Text(
                        '${'Inspection Date'.tr}: $carBackLicenseExpired',
                        style: TextStyle(
                          color:
                              isInspectionExpired ? Colors.red : Colors.green,
                        ),
                      ),
                    ],
                  ),
                ],
              ),
            ),
          );
        }
        return Card(
          child: InkWell(
            onTap: () async {
              ai.allMethodForAI("""
Analyze the extracted car license information and create a JSON object with the following keys:

{
  "make": "",
  "year": "",
  "chassis": "",
  "model": "",
  "engine": "",
  "displacement": "",
  "cylinders": "",
  "fuel": "",
  "color": "",
  "color_hex": "",
  "inspection_date": "",
  "assuranceNumber": "",
  "tax_expiry": ""
}

Important notes:
1. For dates (inspection_date and tax_expiry), use the format YYYY-MM-DD with Latin numerals (0-9).
2. Convert the color name to its corresponding hex color code for the 'color_hex' field.
3. Ensure all numeric values (year, displacement, cylinders) are in Latin numerals.
4. If any information is missing, leave the corresponding field as an empty string.
5. Do not include any explanatory text in the JSON fields, only the extracted values.

Please fill in the JSON object with the extracted information, following these guidelines.
""", 'car_back', ai.driverId);
            },
            child: Column(
              children: [
                Image.network(
                  '${AppLink.server}/card_image/car_back-${ai.driverId}.jpg',
                  height: Get.height * .25,
                  width: double.maxFinite,
                  fit: BoxFit.fitHeight,
                  errorBuilder: (BuildContext context, Object exception,
                      StackTrace? stackTrace) {
                    return Text("Not found any image".tr);
                  },
                ),
                Text(
                  'Capture an Image of Your car license back'.tr,
                  style: AppStyle.title,
                ),
              ],
            ),
          ),
        );
      },
    );
  }

  GetBuilder<RegisterCaptainController> egyptCriminalRecord() {
    return GetBuilder<RegisterCaptainController>(
      builder: (ai) {
        if (ai.responseCriminalRecordEgypt.isNotEmpty) {
          return Card(
            elevation: 4.0,
            shape: RoundedRectangleBorder(
              borderRadius: BorderRadius.circular(16.0),
            ),
            child: Padding(
              padding: const EdgeInsets.all(16.0),
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
                      Text('Criminal Record'.tr, style: AppStyle.headTitle2),
                      IconButton(
                        onPressed: () async {
                          await ai.allMethodForAI("""
Write a JSON object from the following information extracted from the provided Arabic text:

{
  "InspectionResult": "",
  "NationalID": "",
  "FullName": "",
  "IssueDate": "" // Format: YYYY-MM-DD
}

Important notes:
1. For the IssueDate, ensure the date is in YYYY-MM-DD format using Latin numerals (0-9).
2. Add appropriate spaces in all text fields to ensure readability.
3. If any information is missing, leave the corresponding field as an empty string.
4. Ensure all text is properly formatted and spaces are used correctly.
5. Convert any Arabic numerals to Latin numerals (0-9) where applicable.

Please fill in the JSON object with the extracted information, following these guidelines.
""", 'criminalRecord', ai.driverId);
                        },
                        icon: const Icon(Icons.refresh),
                      ),
                    ],
                  ),
                  const SizedBox(height: 8.0),
                  const Divider(color: AppColor.accentColor),
                  const SizedBox(height: 8.0),
                  Text(
                      '${'InspectionResult'.tr}: ${ai.responseCriminalRecordEgypt['InspectionResult']}'),
                  const SizedBox(height: 8.0),
                  Text(
                    '${'FullName'.tr}: ${ai.responseCriminalRecordEgypt['FullName']}',
                    style: AppStyle.title.copyWith(
                        color: ai.responseCriminalRecordEgypt['FullName'] ==
                                ai.responseIdEgyptDriverLicense['name_arabic']
                            ? AppColor.greenColor
                            : AppColor.redColor),
                  ),
                  const SizedBox(height: 8.0),
                  Text(
                      '${'NationalID'.tr}: ${ai.responseCriminalRecordEgypt['NationalID']}'),
                  const SizedBox(height: 8.0),
                  Text(
                      '${'IssueDate'.tr}: ${ai.responseCriminalRecordEgypt['IssueDate']}'),
                ],
              ),
            ),
          );
        }
        return Card(
          child: InkWell(
            onTap: () async {
              await ai.allMethodForAI("""
Write a JSON object from the following information extracted from the provided Arabic text:

{
  "InspectionResult": "",
  "NationalID": "",
  "FullName": "",
  "IssueDate": "" // Format: YYYY-MM-DD
}

Important notes:
1. For the IssueDate, ensure the date is in YYYY-MM-DD format using Latin numerals (0-9).
2. Add appropriate spaces in all text fields to ensure readability.
3. If any information is missing, leave the corresponding field as an empty string.
4. Ensure all text is properly formatted and spaces are used correctly.
5. Convert any Arabic numerals to Latin numerals (0-9) where applicable.

Please fill in the JSON object with the extracted information, following these guidelines.
""", 'criminalRecord', ai.driverId);
            },
            child: Column(
              children: [
                Image.network(
                  '${AppLink.server}/card_image/6.png',
                  height: Get.height * .25,
                  width: double.maxFinite,
                  fit: BoxFit.fitHeight,
                ),
                Text(
                  'Capture an Image of Your Criminal Record'.tr,
                  style: AppStyle.title,
                ),
              ],
            ),
          ),
        );
      },
    );
  }
}
