import 'package:cpt_form/modules/apply/attachment_page.dart';
import 'package:cpt_form/modules/apply/form_payment_page.dart';
import 'package:cpt_form/modules/apply/guest_vehicle_page.dart';
import 'package:cpt_form/modules/apply/large_text_box_page.dart';
import 'package:cpt_form/modules/apply/moving_company_page.dart';
import 'package:cpt_form/modules/apply/moving_date_page.dart';
import 'package:cpt_form/modules/apply/note_management_page.dart';
import 'package:cpt_form/modules/apply/renovation_company_page.dart';
import 'package:cpt_form/modules/apply/renovation_date_page.dart';
import 'package:cpt_form/modules/apply/signature_page.dart';
import 'package:cpt_form/modules/apply/type_of_application_page.dart';
import 'package:cpt_form/modules/apply/vehicle_info_page.dart';
import 'package:cs_resources/generated/assets.dart';
import 'package:cs_resources/generated/l10n.dart';
import 'package:plugin_basic/provider/user_config/user_config_service.dart';
import 'package:router/componentRouter/community_service.dart';
import 'package:router/componentRouter/component_service_manager.dart';

//每一种 formType 对应的详情页面类型
enum DetailPageType {
  vehicleInfo, //车辆信息
  note2Management, //备注给管理员输入框
  signature, //单独的签名页面
  typeOfApplication, //申请类型下拉选
  attachment, //附件
  movingDate, //搬家日期
  movingCompany, //搬家公司信息
  guestVehicleInfo, //访客与车辆信息
  renovationDate, //装修日期
  renovationCompany, //装修公司信息
  largeTextBox, //大说明文本框
  payment, //支付页面
  offlinePayment, //线下支付
}

class FormTypes {
  //对应的type类型 对应的icon的图片与宽高
  static Map<String, Map<String, dynamic>> iconMap = {
    //Access Card-Owner
    '1': {
      'name': S.current.access_card_owner,
      'icon_path': Assets.formAccessCard,
      'width': 39.0,
      'height': 31.5,
    },
    //Access Card-Tenant
    '2': {
      'name': S.current.access_card_tenant,
      'icon_path': Assets.formAccessCard,
      'width': 39.0,
      'height': 31.5,
    },
    //Car Park Cancellation
    '3': {
      'name': S.current.car_park_cancellation,
      'icon_path': Assets.formCarVehicle,
      'width': 39.5,
      'height': 33.5,
    },
    //Moving In
    '4': {
      'name': S.current.moving_in,
      'icon_path': Assets.formMoveInOut,
      'width': 36.5,
      'height': 39.5,
    },
    //Moving Out
    '5': {
      'name': S.current.moving_out,
      'icon_path': Assets.formMoveInOut,
      'width': 36.5,
      'height': 39.5,
    },
    //Overnight Parking
    '6': {
      'name': S.current.overnight_parking,
      'icon_path': Assets.formOvernight,
      'width': 39.0,
      'height': 37.0,
    },
    //Registration of 2nd Vehicle
    '7': {
      'name': S.current.registration_of_2_vehicle,
      'icon_path': Assets.formCarVehicle,
      'width': 39.5,
      'height': 33.5,
    },
    //Renovation
    '8': {
      'name': S.current.renovation,
      'icon_path': Assets.formRenovation,
      'width': 35.5,
      'height': 40.0,
    },
    //Re-Registration of 1st Vehicle-Owner
    '9': {
      'name': S.current.re_registration_of_1_vehicle_owner,
      'icon_path': Assets.formCarVehicle,
      'width': 39.5,
      'height': 33.5,
    },
    //Re-Registration of 1st Vehicle-Owner
    '10': {
      'name': S.current.re_registration_of_1_vehicle_tenant,
      'icon_path': Assets.formCarVehicle,
      'width': 39.5,
      'height': 33.5,
    },
    //Re-Registration of Bicycles
    '11': {
      'name': S.current.re_registration_of_bicycle,
      'icon_path': Assets.formBicycles,
      'width': 39.0,
      'height': 33.5,
    },
    //Vehicle Label Replacement
    '12': {
      'name': S.current.vehicle_label_replacement,
      'icon_path': Assets.formLabeReplace,
      'width': 38.0,
      'height': 27.5,
    },
  };

  // ===================================  Begin  ↓  ===================================

  //type类型对应的详情页面组与对应的数据
  static Map<String, Map<String, dynamic>> buildDetailPageMap(bool enableEdit) {
    return {
      //Access Card-Owner
      '1': {
        'title': S.current.access_card_owner,
        'term_url': 'https://lehuoer.com/privacy.html',
        'detail_pages': [
          DetailPageType.typeOfApplication,
          DetailPageType.note2Management,
          enableEdit ? DetailPageType.payment : DetailPageType.signature,
          if (enableEdit) DetailPageType.offlinePayment,
        ],
        'detail_data': {
          'note_management_txt': S.current.access_card_desc,
          'signature_txt': S.current.signature_access_card,
        }
      },
      //Access Card-Tenant
      '2': {
        'title': S.current.access_card_tenant,
        'term_url': 'https://lehuoer.com/privacy.html',
        'detail_pages': [
          DetailPageType.typeOfApplication,
          DetailPageType.attachment,
          DetailPageType.note2Management,
          enableEdit ? DetailPageType.payment : DetailPageType.signature,
          if (enableEdit) DetailPageType.offlinePayment,
        ],
        'detail_data': {
          'attachment_txt': S.current.access_card_tenant_letter,
          'note_management_txt': S.current.access_card_desc,
          'signature_txt': S.current.signature_access_card,
        }
      },
      //Car Park Cancellation
      '3': {
        'title': S.current.car_park_cancellation,
        'term_url': 'https://lehuoer.com/privacy.html',
        'detail_pages': [
          DetailPageType.vehicleInfo,
          DetailPageType.note2Management,
          DetailPageType.signature,
          if (enableEdit) DetailPageType.offlinePayment,
        ],
        'detail_data': {
          'note_management_txt': '${S.current.car_cancel_txt}\n\n${S.current.car_cancel_txt_1}\n${S.current.car_cancel_txt_2}',
          'signature_txt': S.current.car_cancel_signature_txt(UserConfigService.getState().getDefaultEstateName() ?? "-"),
        }
      },
      //Moving In
      '4': {
        'title': S.current.moving_in,
        'term_url': 'https://lehuoer.com/privacy.html',
        'detail_pages': [
          DetailPageType.movingDate,
          DetailPageType.movingCompany,
          DetailPageType.note2Management,
          enableEdit ? DetailPageType.payment : DetailPageType.signature,
          if (enableEdit) DetailPageType.offlinePayment,
        ],
        'detail_data': {
          'note_management_txt': S.current.moving_in_msg,
          'signature_txt': S.current.signature_moving,
        }
      },
      //Moving Out
      '5': {
        'title': S.current.moving_out,
        'term_url': 'https://lehuoer.com/privacy.html',
        'detail_pages': [
          DetailPageType.movingDate,
          DetailPageType.movingCompany,
          DetailPageType.note2Management,
          enableEdit ? DetailPageType.payment : DetailPageType.signature,
          if (enableEdit) DetailPageType.offlinePayment,
        ],
        'detail_data': {
          'note_management_txt': S.current.moving_in_msg,
          'signature_txt': S.current.signature_moving,
        }
      },
      //Overnight Parking
      '6': {
        'title': S.current.overnight_parking,
        'term_url': 'https://lehuoer.com/privacy.html',
        'detail_pages': [
          DetailPageType.guestVehicleInfo,
          DetailPageType.note2Management,
          DetailPageType.signature,
          if (enableEdit) DetailPageType.offlinePayment,
        ],
        'detail_data': {
          'note_management_txt': S.current.overnight_parking_msg,
          'signature_txt': S.current.signature_vehicle(UserConfigService.getState().getDefaultEstateName() ?? "-"),
        }
      },
      //Registration of 2nd Vehicle
      '7': {
        'title': S.current.registration_of_2_vehicle,
        'term_url': 'https://lehuoer.com/privacy.html',
        'detail_pages': [
          DetailPageType.vehicleInfo,
          DetailPageType.attachment,
          DetailPageType.note2Management,
          DetailPageType.signature,
          if (enableEdit) DetailPageType.offlinePayment,
        ],
        'detail_data': {
          'attachment_txt': '${S.current.label_txt}\n\n${S.current.label_txt_1}\n\n${S.current.label_txt_2}\n\n${S.current.label_txt_3}',
          'note_management_txt': S.current.moving_in_msg,
          'signature_txt': S.current.signature_vehicle(UserConfigService.getState().getDefaultEstateName() ?? "-"),
        }
      },
      //Renovation
      '8': {
        'title': S.current.renovation,
        'term_url': 'https://lehuoer.com/privacy.html',
        'detail_pages': [
          DetailPageType.renovationDate,
          DetailPageType.renovationCompany,
          DetailPageType.largeTextBox,
          DetailPageType.attachment,
          DetailPageType.note2Management,
          enableEdit ? DetailPageType.payment : DetailPageType.signature,
          if (enableEdit) DetailPageType.offlinePayment,
        ],
        'detail_data': {
          'large_txt': S.current.list_of_renovation_works,
          'attachment_txt': S.current.renovation_attachments,
          'note_management_txt': S.current.renovation_note,
          'signature_txt': S.current.signature_renovation,
        }
      },
      //Re-Registration of 1st Vehicle-Owner
      '9': {
        'title': S.current.re_registration_of_1_vehicle_owner,
        'term_url': 'https://lehuoer.com/privacy.html',
        'detail_pages': [
          DetailPageType.vehicleInfo,
          DetailPageType.attachment,
          DetailPageType.note2Management,
          DetailPageType.signature,
          if (enableEdit) DetailPageType.offlinePayment,
        ],
        'detail_data': {
          'attachment_txt': '${S.current.label_txt}\n\n${S.current.label_txt_1}\n\n${S.current.label_txt_2}\n\n${S.current.label_txt_3}',
          'note_management_txt': S.current.moving_in_msg,
          'signature_txt': S.current.signature_vehicle(UserConfigService.getState().getDefaultEstateName() ?? "-"),
        }
      },
      //Re-Registration of 1st Vehicle-Owner
      '10': {
        'title': S.current.re_registration_of_1_vehicle_tenant,
        'term_url': 'https://lehuoer.com/privacy.html',
        'detail_pages': [
          DetailPageType.vehicleInfo,
          DetailPageType.attachment,
          DetailPageType.note2Management,
          DetailPageType.signature,
          if (enableEdit) DetailPageType.offlinePayment,
        ],
        'detail_data': {
          'attachment_txt': '${S.current.label_txt}\n\n${S.current.label_txt_1}\n\n${S.current.label_txt_2}\n\n${S.current.label_txt_3}',
          'note_management_txt': S.current.moving_in_msg,
          'signature_txt': S.current.signature_vehicle(UserConfigService.getState().getDefaultEstateName() ?? "-"),
        }
      },
      //Re-Registration of Bicycles
      '11': {
        'title': S.current.re_registration_of_bicycle,
        'term_url': 'https://lehuoer.com/privacy.html',
        'detail_pages': [
          DetailPageType.typeOfApplication,
          DetailPageType.attachment,
          DetailPageType.note2Management,
          DetailPageType.signature,
          if (enableEdit) DetailPageType.offlinePayment,
        ],
        'detail_data': {
          'attachment_txt': S.current.bicycle_desc,
          'note_management_txt': S.current.bicycle_note,
          'signature_txt': S.current.signature_bicycle,
        }
      },
      //Vehicle Label Replacement
      '12': {
        'title': S.current.vehicle_label_replacement,
        'term_url': 'https://lehuoer.com/privacy.html',
        'detail_pages': [
          DetailPageType.typeOfApplication,
          DetailPageType.attachment,
          DetailPageType.note2Management,
          enableEdit ? DetailPageType.payment : DetailPageType.signature,
          if (enableEdit) DetailPageType.offlinePayment,
        ],
        'detail_data': {
          'attachment_txt': '${S.current.label_txt}\n\n${S.current.label_txt_1}\n\n${S.current.label_txt_2}\n\n${S.current.label_txt_3}',
          'note_management_txt': S.current.label_replace_note,
          'signature_txt': S.current.signature_vehicle(UserConfigService.getState().getDefaultEstateName() ?? "-"),
        }
      },
    };
  }

  // ===================================  Begin  ↓  ===================================

  //根据详情页面类型跳转到对应的详情
  static bool startDetailPageByType(List<DetailPageType>? types, int index) {
    //判断数组是否为空
    if (types == null || types.isEmpty || index >= types.length) return false;

    //去除除数组的第0索引，根据PageType类型判断跳转进入哪一个页面
    final nextPage = types[index];
    switch (nextPage) {
      case DetailPageType.vehicleInfo:
        VehicleInfoPage.startInstance();
        break;
      case DetailPageType.note2Management:
        NoteManagementPage.startInstance();
        break;
      case DetailPageType.signature:
        SignaturePage.startInstance();
        break;
      case DetailPageType.typeOfApplication:
        TypeOfApplicationPage.startInstance();
        break;
      case DetailPageType.attachment:
        AttachmentPage.startInstance();
        break;
      case DetailPageType.movingDate:
        MovingDatePage.startInstance();
        break;
      case DetailPageType.movingCompany:
        MovingCompanyPage.startInstance();
        break;
      case DetailPageType.guestVehicleInfo:
        GuestVehiclePage.startInstance();
        break;
      case DetailPageType.renovationDate:
        RenovationDatePage.startInstance();
        break;
      case DetailPageType.renovationCompany:
        RenovationCompanyPage.startInstance();
        break;
      case DetailPageType.largeTextBox:
        LargeTextBoxPage.startInstance();
        break;
      case DetailPageType.payment:
        FormPaymentPage.startInstance();
        break;
      case DetailPageType.offlinePayment:
        ComponentServiceManager().paymentService.startWithPopOfflinePaymentPage('FormPageRoute');
        break;
    }

    //移除数组的第0索引，避免重复跳转页面
    return true;
  }
}
