import {
    User,
    Users,
    FileText,
    Truck,
    Container,
    Ship,
    Plane,
    Package,
    Briefcase,
    Globe,
    CreditCard,
    DollarSign,
    Calendar,
    Hash,
    MapPin,
    ShieldCheck,
    FileDigit,
    Scale,
} from 'lucide-svelte';

// --- Interfaces ---

export interface CsvUploadItem {
    id: string;
    title: string;
    icon: any;
    group?: string; // For grouping within a tab
    modelTarget?: string; // The backend model this maps to
    description?: string;
    templateUrl?: string; // Path to the template file in static/
    disabled?: boolean; // New property to mark items as "Coming Soon"
}

export interface CsvUploadField {
    name: string;
    label: string;
    type: 'text' | 'select' | 'boolean' | 'date' | 'radio';
    options?: { label: string; value: string | boolean | number }[];
    required?: boolean;
    defaultValue?: any;
}

// Map of Tab ID -> Array of Fields
export const tabSettings: Record<string, CsvUploadField[]> = {
    catalogos: [
        {
            name: 'mode',
            label: 'Modo de Carga',
            type: 'radio',
            options: [
                { label: 'Actualizar', value: 'update' },
                { label: 'Reemplazar', value: 'replace' }
            ],
            defaultValue: 'update'
        }
    ],
    transportes: [
        {
            name: 'mode',
            label: 'Modo de Carga',
            type: 'radio',
            options: [
                { label: 'Actualizar', value: 'update' },
                { label: 'Reemplazar', value: 'replace' }
            ],
            defaultValue: 'update'
        }
    ],
    importacion: [
        {
            name: 'autonumber_remesas',
            label: 'Autonumerar Remesas',
            type: 'boolean',
            defaultValue: false
        },
        {
            name: 'recalculate_dates',
            label: 'Recalcular Fechas',
            type: 'boolean',
            defaultValue: false
        },
        {
            name: 'dateFormat',
            label: 'Formato de Fecha',
            type: 'select',
            options: [
                { label: 'DD/MM/YYYY', value: 'dd/mm/yyyy' },
                { label: 'MM/DD/YYYY', value: 'mm/dd/yyyy' },
                { label: 'YYYY-MM-DD', value: 'yyyy-mm-dd' }
            ],
            defaultValue: 'dd/mm/yyyy'
        }
    ],
    exportacion: [
        {
            name: 'invoice_type',
            label: 'Tipo de Factura',
            type: 'select',
            options: [
                { label: 'AFIJO', value: 'AFIJO' },
                { label: 'NORMAL', value: 'NORMAL' },
            ],
            defaultValue: 'AFIJO',
        },
        {
            name: 'is_regime_change',
            label: 'Es Cambio de Régimen',
            type: 'boolean',
            defaultValue: false,
        },
        {
            name: 'dateFormat',
            label: 'Formato de Fecha',
            type: 'select',
            options: [
                { label: 'DD/MM/YYYY', value: 'dd/mm/yyyy' },
                { label: 'MM/DD/YYYY', value: 'mm/dd/yyyy' },
                { label: 'YYYY-MM-DD', value: 'yyyy-mm-dd' }
            ],
            defaultValue: 'dd/mm/yyyy'
        }
    ]
};

// --- DATA DEFINITIONS (Items only, no config) ---

export const catalogosConfig: CsvUploadItem[] = [
    {
        id: 'customs_brokers',
        title: 'Agentes Aduanales',
        icon: User,
        modelTarget: 'CustomsBroker',
        templateUrl: '/csv/EstructuraCatAgenteAduanal.xls'
    },
    {
        id: 'clients_providers',
        title: 'Clientes y Proveedores',
        icon: Users,
        modelTarget: 'ClientProvider',
        templateUrl: '/csv/EstructuraCatClienteProv.xls'
    },
    {
        id: 'exchange_rates',
        title: 'Tipo de Cambios',
        icon: DollarSign,
        modelTarget: 'ExchangeRate',
        templateUrl: '/csv/EstructuraCatTiposCambio.xls'
    },
    {
        id: 'american_fractions',
        title: 'Fracc. Ame.',
        icon: Globe,
        modelTarget: 'AmericanFraction',
        templateUrl: '/csv/EstructuraCatFraccAme.xls'
    },
    {
        id: 'material_classes',
        title: 'Clases de Materiales',
        icon: Package,
        modelTarget: 'MaterialClass',
        templateUrl: '/csv/EstructuraCatClasesAF.xls'
    },
    {
        id: 'items',
        title: 'Partidas (Permisos)',
        icon: FileText,
        group: 'Permisos',
        modelTarget: 'ItemPermission',
        templateUrl: '/csv/EstructuraCatPartesAF.xls'
    },
    {
        id: 'headers',
        title: 'Encabezados (Permisos)',
        icon: FileText,
        group: 'Permisos',
        modelTarget: 'HeaderPermission',
        disabled: true,
    },
    {
        id: 'historical_fractions',
        title: 'Fracciones Históricas',
        icon: Calendar,
        modelTarget: 'HistoricalFraction',
        disabled: true,
    },
    {
        id: 'pedimentos',
        title: 'Pedimentos',
        icon: FileDigit,
        modelTarget: 'Pedimento',
        templateUrl: '/csv/EstructuraCatPedimentos.xls'
    },
];

export const transportesConfig: CsvUploadItem[] = [
    {
        id: 'transports',
        title: 'Transportes',
        icon: Truck,
        modelTarget: 'Transport',
        templateUrl: '/csv/EstructuraCatTransportes.xls'
    },
    {
        id: 'drivers',
        title: 'Conductores',
        icon: User,
        modelTarget: 'Driver',
        templateUrl: '/csv/EstructuraCatConductor.xls'
    },
    {
        id: 'trailers',
        title: 'Trailers y Cajas',
        icon: Container,
        modelTarget: 'Trailer',
        templateUrl: '/csv/EstructuraCatTrailers.xls'
    },
];

export const importacionConfig: CsvUploadItem[] = [
    // Impo Temp
    {
        id: 'imp_temp_header',
        title: 'Encabezado',
        icon: FileText,
        group: 'Impo. Temp.',
        modelTarget: 'invoice_header',
        templateUrl: '/csv/EstructuraEncFacImpoTemp.xls'
    },
    {
        id: 'imp_temp_details',
        title: 'Partidas',
        icon: Package,
        group: 'Impo. Temp.',
        modelTarget: 'invoice_details',
        templateUrl: '/csv/EstructuraParFacImpoTempAF.xls'
    },
    {
        id: 'imp_temp_series',
        title: 'Series',
        icon: Hash,
        group: 'Impo. Temp.',
        modelTarget: 'InvoiceSeries',
        disabled: true,
    },
    // Impo Def
    {
        id: 'imp_def_header',
        title: 'Encabezado',
        icon: FileText,
        group: 'Impo. Def.',
        modelTarget: 'InvoiceHeader',
        templateUrl: '/csv/EstructuraEncFacImpoDef.xls'
    },
    {
        id: 'imp_def_details',
        title: 'Partidas',
        icon: Package,
        group: 'Impo. Def.',
        modelTarget: 'InvoiceSalesDetails',
        templateUrl: '/csv/EstructuraParFacImpoDefAF.xls'
    },
    {
        id: 'imp_def_series',
        title: 'Series',
        icon: Hash,
        group: 'Impo. Def.',
        modelTarget: 'InvoiceSeries',
        disabled: true,
    },
    // Compras Mex
    {
        id: 'comp_mex_header',
        title: 'Encabezado',
        icon: FileText,
        group: 'Compras Mex.',
        modelTarget: 'InvoiceHeader',
        disabled: true,
    },
    {
        id: 'comp_mex_details',
        title: 'Partidas',
        icon: Package,
        group: 'Compras Mex.',
        modelTarget: 'InvoiceSalesDetails',
        disabled: true,
    },
    {
        id: 'comp_mex_series',
        title: 'Series',
        icon: Hash,
        group: 'Compras Mex.',
        modelTarget: 'InvoiceSeries',
        disabled: true,
    },
];

export const exportacionConfig: CsvUploadItem[] = [
    // Expo Def / Cam. Reg.
    {
        id: 'exp_def_header',
        title: 'Encabezado',
        icon: FileText,
        group: 'Expo. Def./Cam. Reg.',
        modelTarget: 'InvoiceHeader',
        templateUrl: '/csv/EstructuraEncFacExpoCamReg.xls'
    },
    {
        id: 'exp_def_details',
        title: 'Partidas',
        icon: Package,
        group: 'Expo. Def./Cam. Reg.',
        modelTarget: 'InvoiceSalesDetails',
        templateUrl: '/csv/EstructuraParExpoCamReg.xls'
    },
    {
        id: 'exp_def_series',
        title: 'Series',
        icon: Hash,
        group: 'Expo. Def./Cam. Reg.',
        modelTarget: 'InvoiceSeries',
        disabled: true,
    },
    {
        id: 'exp_def_nodes',
        title: 'NODES',
        icon: Briefcase,
        group: 'Expo. Def./Cam. Reg.',
        modelTarget: 'Nodes',
        disabled: true,
    },
    // Expo Rep
    {
        id: 'exp_rep_header',
        title: 'Encabezado',
        icon: FileText,
        group: 'Expo. Rep.',
        modelTarget: 'InvoiceHeader',
        disabled: true,
    },
    {
        id: 'exp_rep_details',
        title: 'Partidas',
        icon: Package,
        group: 'Expo. Rep.',
        modelTarget: 'InvoiceSalesDetails',
        disabled: true,
    },
    {
        id: 'exp_rep_series',
        title: 'Series',
        icon: Hash,
        group: 'Expo. Rep.',
        modelTarget: 'InvoiceSeries',
        disabled: true,
    },
    // Manifiesto
    {
        id: 'manifest_header',
        title: 'Encabezado',
        icon: FileText,
        group: 'Manifiesto',
        modelTarget: 'Manifest',
        disabled: true,
    },
];
