import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:siro_driver/constant/box_name.dart';
import 'package:siro_driver/controller/functions/audio_controller.dart';
import 'package:siro_driver/main.dart';
import 'package:url_launcher/url_launcher.dart';
import '../../../../constant/colors.dart';
import '../../../../constant/links.dart';
import '../../../../constant/style.dart';
import '../../../../controller/functions/gemeni.dart';
import '../../../../controller/functions/package_info.dart';
import '../../../../controller/functions/tts.dart';
import '../../../../print.dart';
import '../../../widgets/elevated_btn.dart';
import '../../../widgets/my_circular_indicator_timer.dart';
import '../../../widgets/my_scafold.dart';
import '../../../widgets/mydialoug.dart';

// --- اقتراحات الألوان الجديدة ---
// يمكنك تعريف هذه الألوان في ملف AppColor.dart الخاص بك
class NewAppColor {
  static const Color primaryColor = Color(0xFF0D47A1); // أزرق داكن
  static const Color accentColor = Color(0xFF1976D2); // أزرق أفتح
  static const Color backgroundColor = Color(0xFFF5F7FA); // رمادي فاتح للخلفية
  static const Color cardColor = Colors.white;
  static const Color textColor = Color(0xFF333333); // أسود ناعم للنصوص
  static const Color subTextColor = Color(0xFF757575); // رمادي للنصوص الفرعية
  static const Color successColor = Color(0xFF2E7D32); // أخضر للنجاح
  static const Color errorColor = Color(0xFFC62828); // أحمر للخطأ
  static const Color borderColor = Color(0xFFE0E0E0); // لون الحدود
}

// --- اقتراحات للخطوط ---
// يمكنك استخدام حزمة google_fonts وتعيين الخط 'Cairo' أو 'Tajawal' للتطبيق
class NewAppStyle {
  static TextStyle get headlineStyle {
    return const TextStyle(
      fontFamily: 'Cairo', // اسم الخط المقترح
      fontSize: 18,
      fontWeight: FontWeight.bold,
      color: NewAppColor.primaryColor,
    );
  }

  static TextStyle get titleStyle {
    return const TextStyle(
      fontFamily: 'Cairo',
      fontSize: 16,
      fontWeight: FontWeight.bold,
      color: NewAppColor.textColor,
    );
  }

  static TextStyle get bodyStyle {
    return const TextStyle(
      fontFamily: 'Cairo',
      fontSize: 14,
      color: NewAppColor.subTextColor,
      height: 1.5,
    );
  }

  static TextStyle get valueStyle {
    return const TextStyle(
      fontFamily: 'Cairo',
      fontSize: 15,
      fontWeight: FontWeight.w600,
      color: NewAppColor.textColor,
    );
  }
}

class SyrianCardAI extends StatelessWidget {
  SyrianCardAI({super.key});
  final TextToSpeechController textToSpeechController =
      Get.put(TextToSpeechController());

  @override
  Widget build(BuildContext context) {
    Get.put(AI());
    WidgetsBinding.instance.addPostFrameCallback((_) {
      checkForUpdate(context);
    });
    return MyScafolld(
      // تم تغيير لون الخلفية للتصميم الجديد
      // backgroundColor: NewAppColor.backgroundColor,
      title: "Approve Driver Documents".tr,
      action: GetBuilder<AI>(builder: (cont) {
        return IconButton(
          onPressed: () {
            cont.isLoading = false;
            cont.update();
          },
          icon: const Icon(Icons.refresh, color: NewAppColor.primaryColor),
        );
      }),
      body: [
        GetBuilder<AI>(builder: (controller) {
          return controller.isLoading
              ? MyCircularProgressIndicatorWithTimer(
                  isLoading: controller.isLoading,
                )
              : Padding(
                  padding: const EdgeInsets.symmetric(
                      horizontal: 12.0, vertical: 8.0),
                  child: Column(
                    children: [
                      // --- زر "التالي" بتصميم جديد ---
                      if (controller.licenceFrontSy.isNotEmpty &&
                          controller.licenceBackSy.isNotEmpty &&
                          (controller.idFrontSy.isNotEmpty) &&
                          (controller.idBackSy.isNotEmpty) &&
                          controller.vehicleFrontSy.isNotEmpty &&
                          controller.vehicleBackSy.isNotEmpty)
                        Padding(
                          padding: const EdgeInsets.only(bottom: 16.0),
                          child: MyElevatedButton(
                            title: 'التالي'.tr,
                            // استخدام اللون الجديد للنجاح
                            kolor: NewAppColor.successColor,
                            onPressed: () {
                              controller.addDriverAndCarEgypt();
                            },
                          ),
                        ),
                      Expanded(
                        child: ListView(
                          children: [
                            // --- فيديو الشرح بتصميم جديد ---
                            VideoButton(),
                            const SizedBox(height: 16),
                            egyptDriverLicense(),
                            const SizedBox(height: 16),
                            syriaDriverLicenseBack(),
                            const SizedBox(height: 16),
                            syriaVehicleCardFront(),
                            const SizedBox(height: 16),
                            syriaVehicleCardBack(),
                            const SizedBox(height: 16),
                            syriaIdCardFront(),
                            const SizedBox(height: 16),
                            syriaDriverIDBack(),
                            const SizedBox(height: 16),
                            // egyptCriminalRecord(),
                            // const SizedBox(height: 24),
                          ],
                        ),
                      ),
                    ],
                  ),
                );
        }),
        // --- شاشة الموافقة بتصميم جديد ---
        Positioned(
          top: 0,
          bottom: 0,
          right: 0,
          left: 0,
          child: GetBuilder<AI>(builder: (controller) {
            return controller.approved == false
                // --- إضافة خلفية معتمة ---
                ? Container(
                    color: Colors.black.withOpacity(0.6),
                    child: Center(
                      child: Container(
                        margin: const EdgeInsets.all(24),
                        padding: const EdgeInsets.all(24),
                        decoration: BoxDecoration(
                          color: Colors.white,
                          borderRadius: BorderRadius.circular(20),
                          boxShadow: [
                            BoxShadow(
                              color: Colors.black.withOpacity(0.2),
                              blurRadius: 15,
                              spreadRadius: 5,
                            )
                          ],
                        ),
                        child: Column(
                          mainAxisSize: MainAxisSize.min,
                          crossAxisAlignment: CrossAxisAlignment.center,
                          children: [
                            Text(
                              "Approve Driver Documents".tr,
                              style: NewAppStyle.headlineStyle,
                            ),
                            const SizedBox(height: 16),
                            Text(
                              "To become a ride-sharing driver on the Siro app, you need to upload your driver's license, ID document, and car registration document. Our AI system will instantly review and verify their authenticity in just 2-3 minutes. If your documents are approved, you can start working as a driver on the Siro app. Please note, submitting fraudulent documents is a serious offense and may result in immediate termination and legal consequences."
                                  .tr,
                              style: NewAppStyle.bodyStyle,
                              textAlign: TextAlign.center,
                            ),
                            const SizedBox(height: 24),
                            // --- زر الاستماع بتصميم جديد ---
                            TextButton.icon(
                              style: TextButton.styleFrom(
                                foregroundColor: NewAppColor.accentColor,
                                shape: RoundedRectangleBorder(
                                  borderRadius: BorderRadius.circular(12),
                                ),
                                padding: const EdgeInsets.symmetric(
                                    horizontal: 20, vertical: 10),
                              ),
                              onPressed: () async {
                                controller.startTimer();
                                if (box.read(BoxName.lang) == 'ar') {
                                  await Get.put(AudioController())
                                      .playAudio1('assets/aggrement.wav');
                                } else {
                                  await textToSpeechController.speakText(
                                      'To become a ride-sharing driver on the Siro app...'
                                          .tr);
                                }
                              },
                              icon: const Icon(Icons.volume_up_outlined,
                                  size: 30),
                              label: Text('اضغط للاستماع'.tr,
                                  style: AppStyle.title.copyWith(
                                      color: NewAppColor.accentColor)),
                            ),
                            const SizedBox(height: 24),
                            // --- أزرار الموافقة والرفض بتصميم جديد ---
                            controller.isTimerComplete
                                ? Row(
                                    children: [
                                      Expanded(
                                        child: MyElevatedButton(
                                            title: 'إلغاء'.tr,
                                            kolor: NewAppColor.errorColor,
                                            onPressed: () {
                                              MyDialog().getDialog(
                                                  'سيتم إلغاء التسجيل'.tr, '',
                                                  () async {
                                                Get.back();
                                                Get.back();
                                              });
                                            }),
                                      ),
                                      const SizedBox(width: 16),
                                      Expanded(
                                        child: MyElevatedButton(
                                            title: 'أوافق'.tr,
                                            kolor: NewAppColor.successColor,
                                            onPressed: () {
                                              controller.setApproved();
                                            }),
                                      ),
                                    ],
                                  )
                                : Column(
                                    children: [
                                      CircularProgressIndicator(
                                        value: controller.progressValue,
                                        color: NewAppColor.primaryColor,
                                      ),
                                      const SizedBox(height: 8),
                                      Text(
                                        '${'الوقت المتبقي'.tr}: ${controller.remainingSeconds} ${"ثانية".tr}',
                                        style: NewAppStyle.bodyStyle,
                                      ),
                                    ],
                                  ),
                          ],
                        ),
                      ),
                    ),
                  )
                : const SizedBox();
          }),
        )
      ],
      isleading: true,
    );
  }

  // --- واجهة عرض بيانات الوثيقة ---
  Widget _buildDocumentDataCard({
    required String title,
    required VoidCallback onRefresh,
    required List<Widget> children,
  }) {
    return Card(
      elevation: 4.0,
      color: NewAppColor.cardColor,
      shape: RoundedRectangleBorder(
        borderRadius: BorderRadius.circular(16.0),
        side: BorderSide(color: NewAppColor.borderColor, width: 1),
      ),
      shadowColor: NewAppColor.primaryColor.withOpacity(0.1),
      child: Padding(
        padding: const EdgeInsets.all(16.0),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: [
                Text(title, style: NewAppStyle.headlineStyle),
                IconButton(
                  onPressed: onRefresh,
                  icon:
                      const Icon(Icons.refresh, color: NewAppColor.accentColor),
                ),
              ],
            ),
            const Divider(
                height: 24, thickness: 1, color: NewAppColor.borderColor),
            ...children,
          ],
        ),
      ),
    );
  }

  // --- واجهة التقاط صورة الوثيقة ---
  Widget _buildCaptureCard({
    required String title,
    required String imagePath,
    required VoidCallback onTap,
  }) {
    return GestureDetector(
      onTap: onTap,
      child: Card(
        clipBehavior: Clip.antiAlias,
        elevation: 2.0,
        shape: RoundedRectangleBorder(
          borderRadius: BorderRadius.circular(16.0),
        ),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.stretch,
          children: [
            Image.asset(
              imagePath,
              height: Get.height * .20,
              fit: BoxFit.cover,
              // --- في حال لم يتم العثور على الصورة ---
              errorBuilder: (context, error, stackTrace) {
                return Container(
                  height: Get.height * .20,
                  color: NewAppColor.borderColor,
                  child: const Icon(
                    Icons.camera_alt_outlined,
                    size: 50,
                    color: NewAppColor.subTextColor,
                  ),
                );
              },
            ),
            Container(
              padding: const EdgeInsets.all(16.0),
              color: NewAppColor.cardColor,
              child: Text(
                title,
                style: AppStyle.title,
                textAlign: TextAlign.center,
              ),
            ),
          ],
        ),
      ),
    );
  }

  // --- ويدجت لعرض معلومة (سطر) ---
  Widget _infoRow(String label, String? value, {Color? valueColor}) {
    return Padding(
      padding: const EdgeInsets.symmetric(vertical: 6.0),
      child: Row(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Text('$label: ', style: NewAppStyle.bodyStyle),
          Expanded(
            child: Text(
              value ?? 'غير متوفر',
              style: NewAppStyle.valueStyle.copyWith(color: valueColor),
            ),
          ),
        ],
      ),
    );
  }

  GetBuilder<AI> egyptDriverLicense() {
    return GetBuilder<AI>(
      builder: (ai) {
        if (ai.licenceFrontSy.isNotEmpty) {
          final data = ai.licenceFrontSy;

          DateTime? expiryDateTime;
          bool isExpired = false;
          if (data['expiry_date'] != null) {
            expiryDateTime = DateTime.tryParse(data['expiry_date']);
            isExpired = expiryDateTime != null &&
                expiryDateTime.isBefore(DateTime.now());
          }

          // بطاقة «رخصة القيادة – الوجه الأمامي» بتنسيق مضغوط وأيقونات
          return Card(
            elevation: 2,
            color: NewAppColor.cardColor,
            shape: RoundedRectangleBorder(
              borderRadius: BorderRadius.circular(14),
              side: BorderSide(color: NewAppColor.borderColor, width: .8),
            ),
            child: Padding(
              padding: const EdgeInsets.all(12),
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  // العنوان + زر التحديث
                  Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
                      Text('رخصة القيادة – الوجه الأمامي'.tr,
                          style: NewAppStyle.headlineStyle),
                      IconButton(
                        icon: const Icon(Icons.refresh,
                            size: 20, color: NewAppColor.accentColor),
                        splashRadius: 18,
                        onPressed: () async => await ai
                            .pickAndSendImage('driving_license_sy_front'),
                      ),
                    ],
                  ),
                  const SizedBox(height: 8),

                  // سطر الاسم الكامل

                  Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
                      if (data['name_arabic'] != null)
                        _iconInfo(Icons.person, data['name_arabic']!),
                      if (data['birth_place'] != null)
                        _iconInfo(Icons.location_city, data['birth_place']!),
                    ],
                  ),
                  const SizedBox(height: 8),

                  // بقية الحقول داخل Wrap لتقليل الطول
                  Wrap(
                    spacing: 12,
                    runSpacing: 8,
                    children: [
                      if (data['national_number'] != null)
                        _iconInfo(Icons.badge, data['national_number']!),
                      if (data['civil_registry'] != null)
                        _iconInfo(Icons.location_on, data['civil_registry']!),
                      if (data['blood_type'] != null)
                        _iconInfo(Icons.water_drop, data['blood_type']!),
                      if (data['birth_year'] != null)
                        _iconInfo(Icons.calendar_today, data['birth_year']!),
                    ],
                  ),
                ],
              ),
            ),
          );
        }
        return _buildCaptureCard(
          title: 'التقط صورة لرخصة القيادة'.tr,
          imagePath: 'assets/images/1.png',
          onTap: () async {
            await ai.pickAndSendImage('driving_license_sy_front');
          },
        );
      },
    );
  }

  GetBuilder<AI> syriaDriverLicenseBack() {
    return GetBuilder<AI>(
      builder: (ai) {
        if (ai.licenceBackSy.isNotEmpty) {
          final data = ai.licenceBackSy;

          // صلاحية الرخصة
          final DateTime? expDate =
              DateTime.tryParse(data['expiry_date'] ?? '');
          final bool expired =
              expDate != null && expDate.isBefore(DateTime.now());
          final Color expColor = expired
              ? NewAppColor.errorColor // أحمر إن انتهت
              : NewAppColor.successColor; // أخضر إن صالحة

          return Card(
            elevation: 2,
            color: NewAppColor.cardColor,
            shape: RoundedRectangleBorder(
              borderRadius: BorderRadius.circular(14),
              side: BorderSide(color: NewAppColor.borderColor, width: .8),
            ),
            child: Padding(
              padding: const EdgeInsets.all(12),
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  // عنوان البطاقة + زر الإنعاش
                  Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
                      Text('رخصة القيادة – الوجه الخلفي'.tr,
                          style: NewAppStyle.headlineStyle),
                      IconButton(
                        splashRadius: 18,
                        icon: const Icon(Icons.refresh,
                            size: 20, color: NewAppColor.accentColor),
                        onPressed: () async => await ai
                            .pickAndSendImage('driving_license_sy_back'),
                      ),
                    ],
                  ),
                  const SizedBox(height: 8),

                  // صفّ أول (الفئة + الرقم)
                  Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
                      if (data['license_category'] != null)
                        _iconInfo(
                            Icons.star, data['license_category']!), // D1 / D2…
                      if (data['license_number'] != null)
                        _iconInfo(
                            Icons.confirmation_number, data['license_number']!),
                    ],
                  ),
                  const SizedBox(height: 8),

                  // صفّ ثانٍ (التواريخ) مع تلوين تاريخ الصلاحية
                  Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
                      if (data['issue_date'] != null)
                        _iconInfo(Icons.event, data['issue_date']!),
                      if (data['expiry_date'] != null)
                        _iconInfo(Icons.event_busy, data['expiry_date']!,
                            valueColor: expColor),
                    ],
                  ),
                ],
              ),
            ),
          );
        }

        // بطاقة الالتقاط الافتراضية
        return _buildCaptureCard(
          title: 'التقط صورة الوجه الخلفي للرخصة'.tr,
          imagePath: 'assets/images/5.png',
          onTap: () async =>
              await ai.pickAndSendImage('driving_license_sy_back'),
        );
      },
    );
  }

  GetBuilder<AI> syriaDriverIDBack() {
    return GetBuilder<AI>(
      builder: (ai) {
        // استلمنا الحقول الأربعة فقط (governorate-address-gender-issue_date)
        if (ai.idBackSy.isNotEmpty) {
          final data = ai.idBackSy;

          return Card(
            elevation: 2,
            color: NewAppColor.cardColor,
            shape: RoundedRectangleBorder(
              borderRadius: BorderRadius.circular(14),
              side: BorderSide(color: NewAppColor.borderColor, width: .8),
            ),
            child: Padding(
              padding: const EdgeInsets.all(12),
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  // العنوان + زر التحديث
                  Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
                      Text('بطاقة الهوية – الوجه الخلفي'.tr,
                          style: NewAppStyle.headlineStyle),
                      IconButton(
                        splashRadius: 18,
                        icon: const Icon(Icons.refresh,
                            size: 20, color: NewAppColor.accentColor),
                        onPressed: () async =>
                            await ai.pickAndSendImage('id_back_sy'),
                      ),
                    ],
                  ),
                  const SizedBox(height: 8),

                  // المحافظة + العنوان
                  Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
                      if (data['governorate'] != null)
                        _iconInfo(Icons.location_city, data['governorate']!),
                      if (data['address'] != null)
                        _iconInfo(Icons.home, data['address']!),
                    ],
                  ),
                  const SizedBox(height: 8),

                  // الجنس + تاريخ الإصدار
                  Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
                      if (data['gender'] != null)
                        _iconInfo(Icons.person, data['gender']!),
                      if (data['issue_date'] != null)
                        _iconInfo(Icons.event, data['issue_date']!),
                    ],
                  ),
                ],
              ),
            ),
          );
        }

        // البطاقة الافتراضية لالتقاط الصورة
        return _buildCaptureCard(
          title: 'التقط صورة للوجه الخلفي للهوية'.tr,
          imagePath: 'assets/images/4.png',
          onTap: () async => await ai.pickAndSendImage('id_back_sy'),
        );
      },
    );
  }

  /// عنصر (أيقونة + قيمة) مع لون نص مخصّص عند الحاجة
  Widget _iconInfo(IconData icon, String value, {Color? valueColor}) {
    return Row(
      mainAxisSize: MainAxisSize.min,
      children: [
        Icon(icon, size: 18, color: NewAppColor.accentColor),
        const SizedBox(width: 4),
        Flexible(
          child: Text(
            value.tr,
            style: NewAppStyle.bodyStyle.copyWith(color: valueColor),
            overflow: TextOverflow.ellipsis,
          ),
        ),
      ],
    );
  }

  GetBuilder<AI> syriaIdCardFront() {
    // أبقِ الاسم القديم إذا أردت
    return GetBuilder<AI>(
      builder: (ai) {
        if (ai.idFrontSy.isNotEmpty) {
          // غيّر المفتاح حسب متغيرك
          final data = ai.idFrontSy;

          return Card(
            elevation: 2,
            color: NewAppColor.cardColor,
            shape: RoundedRectangleBorder(
              borderRadius: BorderRadius.circular(14),
              side: BorderSide(color: NewAppColor.borderColor, width: .8),
            ),
            child: Padding(
              padding: const EdgeInsets.all(12),
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  // العنوان + زر التحديث
                  Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
                      Text('بطاقة الهوية – الوجه الأمامي'.tr,
                          style: NewAppStyle.headlineStyle),
                      IconButton(
                        splashRadius: 18,
                        icon: const Icon(Icons.refresh,
                            size: 20, color: NewAppColor.accentColor),
                        onPressed: () async => await ai.pickAndSendImage(
                          'id_front_sy', // أو id_front حسب تسمية end-point
                        ),
                      ),
                    ],
                  ),
                  const SizedBox(height: 8),

                  // سطر الاسم الكامل
                  if (data['full_name'] != null)
                    _iconInfo(Icons.person, data['full_name']!),
                  const SizedBox(height: 8),

                  // صفّ (الرقم الوطني + تاريخ الميلاد)
                  Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
                      if (data['national_number'] != null)
                        _iconInfo(Icons.badge, data['national_number']!),
                      if (data['dob'] != null)
                        _iconInfo(Icons.cake, data['dob']!),
                    ],
                  ),
                  const SizedBox(height: 8),

                  // العنوان كامل بمفرده
                  if (data['address'] != null)
                    _iconInfo(Icons.home, data['address']!),
                ],
              ),
            ),
          );
        }

        // كارد الالتقاط الافتراضية
        return _buildCaptureCard(
          title: 'التقط صورة للوجه الأمامي للهوية'.tr,
          imagePath: 'assets/images/2.png',
          onTap: () async => await ai.pickAndSendImage('id_front_sy'),
        );
      },
    );
  }

  GetBuilder<AI> syriaVehicleCardFront() {
    // يمكنك إبقاء الاسم القديم إن شئت
    return GetBuilder<AI>(
      builder: (ai) {
        if (ai.vehicleFrontSy.isNotEmpty) {
          final data = ai.vehicleFrontSy;

          // تاريخ الفحص القادم للفحص الدوري (inspection_date)
          final DateTime? nextCheck =
              DateTime.tryParse(data['inspection_date'] ?? '');
          final bool overdue =
              nextCheck != null && nextCheck.isBefore(DateTime.now());
          final Color checkColor =
              overdue ? NewAppColor.errorColor : NewAppColor.successColor;

          return Card(
            elevation: 2,
            color: NewAppColor.cardColor,
            shape: RoundedRectangleBorder(
              borderRadius: BorderRadius.circular(14),
              side: BorderSide(color: NewAppColor.borderColor, width: .8),
            ),
            child: Padding(
              padding: const EdgeInsets.all(12),
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  // العنوان + تحديث
                  Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
                      Text('رخصة المركبة – الوجه الأمامي'.tr,
                          style: NewAppStyle.headlineStyle),
                      IconButton(
                        splashRadius: 18,
                        icon: const Icon(Icons.refresh,
                            size: 20, color: NewAppColor.accentColor),
                        onPressed: () async => await ai.pickAndSendImage(
                          'vehicle_license_sy_front',
                        ),
                      ),
                    ],
                  ),
                  const SizedBox(height: 8),

                  // الصف الأوّل (لوحة + مالك)
                  Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
                      if (data['car_plate'] != null)
                        _iconInfo(Icons.directions_car, data['car_plate']!),
                      if (data['owner'] != null)
                        _iconInfo(Icons.person, data['owner']!),
                    ],
                  ),
                  const SizedBox(height: 8),

                  // الصف الثاني (VIN + اللون)
                  Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
                      if (data['vin'] != null)
                        _iconInfo(Icons.confirmation_num, data['vin']!),
                      if (data['color'] != null)
                        _iconInfo(Icons.palette, data['color']!),
                    ],
                  ),
                  const SizedBox(height: 8),

                  // الصف الثالث (تاريخ المنح + الفحص القادم)
                  Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
                      if (data['issue_date'] != null)
                        _iconInfo(Icons.event, data['issue_date']!),
                      if (data['inspection_date'] != null)
                        _iconInfo(
                            Icons.event_available, data['inspection_date']!,
                            valueColor: checkColor),
                    ],
                  ),
                ],
              ),
            ),
          );
        }

        // لو لم تُرفع صورة بعد
        return _buildCaptureCard(
          title: 'التقط صورة لوجه رخصة المركبة'.tr,
          imagePath: 'assets/images/6.png',
          onTap: () async =>
              await ai.pickAndSendImage('vehicle_license_sy_front'),
        );
      },
    );
  }

  GetBuilder<AI> syriaVehicleCardBack() {
    // أبقِ الاسم القديم إن أردت
    return GetBuilder<AI>(
      builder: (ai) {
        if (ai.vehicleBackSy.isNotEmpty) {
          final data = ai.vehicleBackSy;

          return Card(
            elevation: 2,
            color: NewAppColor.cardColor,
            shape: RoundedRectangleBorder(
              borderRadius: BorderRadius.circular(14),
              side: BorderSide(color: NewAppColor.borderColor, width: .8),
            ),
            child: Padding(
              padding: const EdgeInsets.all(12),
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  // العنوان + زر تحديث
                  Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
                      Text('رخصة المركبة – الوجه الخلفي'.tr,
                          style: NewAppStyle.headlineStyle),
                      IconButton(
                        splashRadius: 18,
                        icon: const Icon(Icons.refresh,
                            size: 20, color: NewAppColor.accentColor),
                        onPressed: () async => await ai.pickAndSendImage(
                          'vehicle_license_sy_back',
                        ),
                      ),
                    ],
                  ),
                  const SizedBox(height: 8),

                  // صفّ (الشركة + الطراز)
                  Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
                      if (data['make'] != null)
                        _iconInfo(Icons.factory, data['make']!),
                      if (data['model'] != null)
                        _iconInfo(Icons.directions_car_filled, data['model']!),
                    ],
                  ),
                  const SizedBox(height: 8),

                  // صفّ (سنة الصنع + اللون)
                  Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
                      if (data['year'] != null)
                        _iconInfo(Icons.calendar_today, data['year']!),
                      if (data['fuel'] != null)
                        _iconInfo(Icons.local_gas_station, data['fuel']!),
                    ],
                  ),
                  const SizedBox(height: 8),

                  // رقم الهيكل بمفرده (قد يكون طويلًا)
                  if (data['chassis'] != null)
                    _iconInfo(Icons.confirmation_num, data['chassis']!),
                ],
              ),
            ),
          );
        }

        // بطاقة الالتقاط الافتراضية
        return _buildCaptureCard(
          title: 'التقط صورة لخلفية رخصة المركبة'.tr,
          imagePath: 'assets/images/3.png',
          onTap: () async =>
              await ai.pickAndSendImage('vehicle_license_sy_back'),
        );
      },
    );
  }

  GetBuilder<AI> egyptCriminalRecord() {
    return GetBuilder<AI>(
      builder: (ai) {
        if (ai.responseCriminalRecordEgypt.isNotEmpty) {
          return _buildDocumentDataCard(
            title: 'صحيفة الحالة الجنائية'.tr,
            onRefresh: () async {
              await ai.allMethodForAI(
                (ai.prompts[5]['prompt'].toString()),
                AppLink.uploadEgypt,
                'criminalRecord',
              );
            },
            children: [
              _infoRow('نتيجة الفحص'.tr,
                  ai.responseCriminalRecordEgypt['InspectionResult']),
              _infoRow(
                'الاسم الكامل'.tr,
                ai.responseCriminalRecordEgypt['FullName'],
                valueColor: (ai.responseCriminalRecordEgypt['FullName']) ==
                        (ai.responseIdEgyptDriverLicense['name_arabic'])
                    ? NewAppColor.successColor
                    : NewAppColor.errorColor,
              ),
              _infoRow('الرقم القومي'.tr,
                  ai.responseCriminalRecordEgypt['NationalID']),
            ],
          );
        }
        return _buildCaptureCard(
          title: 'التقط صورة لصحيفة الحالة الجنائية'.tr,
          imagePath: 'assets/images/6.png',
          onTap: () async {
            await ai.allMethodForAI(
              (ai.prompts[5]['prompt'].toString()),
              AppLink.uploadEgypt,
              'criminalRecord',
            );
          },
        );
      },
    );
  }
}

// --- واجهة عرض الأقسام غير المصرية (بدون تغيير) ---

// --- زر الفيديو بتصميم جديد ---
class VideoButton extends StatelessWidget {
  final String videoUrl =
      "https://youtube.com/shorts/fC0RmYH5B_0?feature=share";

  @override
  Widget build(BuildContext context) {
    return Card(
      elevation: 2,
      shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
      child: InkWell(
        onTap: () async {
          if (await canLaunchUrl(Uri.parse(videoUrl))) {
            await launchUrl(Uri.parse(videoUrl));
          } else {
            Get.snackbar('خطأ', 'لا يمكن فتح الفيديو');
          }
        },
        borderRadius: BorderRadius.circular(12),
        child: Padding(
          padding: const EdgeInsets.symmetric(horizontal: 16.0, vertical: 12.0),
          child: Row(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              const Icon(Icons.play_circle_outline,
                  color: NewAppColor.accentColor, size: 28),
              const SizedBox(width: 12),
              Text(
                "شاهد فيديو الشرح".tr,
                style: AppStyle.title.copyWith(color: NewAppColor.accentColor),
              ),
            ],
          ),
        ),
      ),
    );
  }
}
