import { TableColumn } from "../types/common";
import { ICircuit } from "../types/circuit";
import { MOCK_ADDRESSES } from ".";

export const _CIRCUIT_STATUS = [
  { value: "controle", label: "Contrôlé" },
  { value: "non_controle", label: "Non Contrôlé" },
];

export const _TRAJET_DUREES = [
  { value: "15", label: "15 minutes" },
  { value: "30", label: "30 minutes" },
  { value: "45", label: "45 minutes" },
  { value: "60", label: "1 heure" },
  { value: "90", label: "1 heure 30" },
  { value: "120", label: "2 heures" }
];


export const _circuits = [...Array(55)].map((_, index) => {
  const startDate = new Date(2002 + Math.floor(index / 12), index % 12, 15);
  const endDate = new Date(startDate.getFullYear() + 2, Math.floor(Math.random() * 12), 1);
  const circuitCode = `CIR-2024-${String.fromCharCode(65 + (index % 26))}${String.fromCharCode(65 + (Math.floor(index / 26)))}`;
  const mockAddress = MOCK_ADDRESSES[index % 4];
  
  return {
    id: (index + 1).toString(),
    etat: index % 3 === 0 ? 'controle' : 'non_controle',
    codeCircuit: circuitCode,
    intitule: `Ligne ${['Nord', 'Sud', 'Est', 'Ouest'][index % 4]}`,
    chauffeur: `Chauffeur ${index + 1}`,
    dateDebut: startDate.toISOString().split('T')[0],
    dateDernierAvenant: new Date(startDate.getTime() + Math.random() * (endDate.getTime() - startDate.getTime())).toISOString().split('T')[0],
    dateFin: endDate.toISOString().split('T')[0],
    etablissement: ['Les Champs', 'La Colline', 'Le Rivage', 'La Forêt'][index % 4],
    adresseEtablissement: mockAddress,
    numeroContrat: `CT-${(index + 1).toString().padStart(5, '0')}`,
    departement: `Région ${['Est', 'Ouest', 'Nord', 'Sud'][index % 4]}`,
    numeroLot: `BCI${(256579345 + index).toString().padStart(9, '0')}`,
    isActive: Math.random() < 0.6,
    typeCalcul: '',
    colorCode: '',
  };
});

export const circuitOptions = _circuits.map((circuit) => ({
  label: `${circuit.intitule} (${circuit.codeCircuit})`,
  value: circuit.id
}));

export const getEtatLabel = (status: string): string => {
  const statusObj = _CIRCUIT_STATUS.find(s => s.value === status);
  return statusObj ? statusObj.label : "Inconnu";
};

export const DEFAULT_CIRCUIT_TABLE_HEAD : TableColumn[] = [
  { id: 'id', label: 'N° circuit', type: 'text',align: 'center' },
  { id: 'circuitState', label: 'État', type: 'status',align: 'left' },
  { id: 'circuitCode', label: 'Code circuit', type: 'text',align: 'left' },
  { id: 'titled', label: 'Intitulé', type: 'text',align: 'left' },
  { id: 'driverName', label: 'Chauffeur', type: 'text',align: 'left' },
  { id: 'startDate', label: 'A partir du', type: 'date',align: 'center' },
  { id: 'lastAmendmentDate', label: 'Dernier avenant', type: 'date',align: 'center' },
  { id: 'endDate', label: 'Fin de circuit', type: 'date',align: 'center' },
  { id: 'establishmentName', label: 'Établissement', type: 'text',align: 'left' },
  { id: 'establishmentAddress', label: 'Adresse établissement', type: 'text',align: 'left' },
  { id: 'contract', label: 'Contrat', type: 'text',align: 'left' },
  { id: 'departmentName', label: 'Département', type: 'text',align: 'left' },
  { id: 'lotNames', label: 'N° de lot', type: 'text', align: 'left' },
  { id: 'isActive', label: 'Active', type: 'boolean',align: 'center' },
  { id: 'createdAt', label: 'Créé le', type: 'date', align: 'center' },
  { id: '', label: 'Action' },
];

export const INITIAL_CIRCUIT_DATA: ICircuit = {
  id: '',
  etat: 'non_controle',
  codeCircuit: '',
  intitule: '',
  chauffeur: '',
  dateDebut: '',
  dateDernierAvenant: '',
  dateFin: '',
  etablissement: '',
  adresseEtablissement:{
    address: '',
    lat: 0,
    lng: 0,
    city: '',
    postalCode: '',
    country: '',
    formattedAddress: ''
  },
  numeroContrat: '',
  departement: '',
  numeroLot: '',
  typeCalcul: '',
  colorCode: '',
  isActive: true,
  dureeTrajet: '',
  observation: '',
};

