import {
	Archive,
	ArrowDownToLine,
	ArrowUpFromLine,
	BadgeCheck,
	ChartPie,
	Database,
	FileSearch,
	FileText,
	FolderArchive,
	Frame,
	GalleryVerticalEnd,
	Hash,
	LayoutDashboard,
	Package,
	Settings2,
	Shield,
	Ship,
	Truck,
	Users,
	Book,
} from '@lucide/svelte';
import { m } from '$lib/i18n/messages';
import { Title } from '../ui/alert';

export interface NavItem {
	title: string;
	url: string;
	permission?: string;
}

export interface NavMainItem {
	title: string;
	url: string;
	icon: any;
	isActive?: boolean;
	permission?: string;
	items?: NavItem[];
}

export interface Project {
	name: string;
	url: string;
	icon: any;
}

export interface Team {
	name: string;
	logo: any;
	plan: string;
}

export interface User {
	name: string;
	email: string;
	avatar: string;
}

export interface SidebarData {
	user: User;
	teams: Team[];
	navMain: NavMainItem[];
	projects: Project[];
}

// Función que retorna los datos del sidebar con traducciones
export function getSidebarData(): SidebarData {
	return {
		user: {
			name: "", // Se llena dinámicamente desde Keycloak
			email: "", // Se llena dinámicamente desde Keycloak
			avatar: "", // Se llena dinámicamente desde Keycloak
		},
		teams: [
			{
				name: "Anexo76",
				logo: GalleryVerticalEnd,
				plan: "Enterprise",
			},
		],
		navMain: [
			{
				title: m["sidebar.dashboard"](),
				url: "/dashboard",
				icon: LayoutDashboard,
				items: [],
			},
			{
				title: m["sidebar.audit_logs"](),
				url: "/dashboard/audit_logs",
				icon: Shield,
				items: [],
				permission: 'audit_logs.view',
			},
			{
				title: m["sidebar.bulk_upload.title"](),
				url: "#",
				icon: ArrowUpFromLine,
				items: [
					{
						title: m["sidebar.bulk_upload.entry"](),
						url: "/dashboard/csv-upload",
						permission: "csv_upload.process",
					},
				],
			},

			{
				title: m["sidebar.reference_data.title"](),
				url: "/dashboard",
				icon: Database,
				items: [
					{
						title: m["sidebar.reference_data.codes_pedimento_regimen"](),
						url: "/dashboard/reference_data/code_pedimento_regimens",
						permission: "ref_pedimento_regimens.view",
					},
					{
						title: m["sidebar.reference_data.containers"](),
						url: "/dashboard/reference_data/containers",
						permission: "ref_containers.view",
					},
					{
						title: m["sidebar.reference_data.countries"](),
						url: "/dashboard/reference_data/countries",
						permission: "ref_countries.view",
					},
					{
						title: m["sidebar.reference_data.currency_types"](),
						url: "/dashboard/reference_data/currency_types",
						permission: "ref_currency_types.view",
					},
					{
						title: m["sidebar.reference_data.customs_sections"](),
						url: "/dashboard/reference_data/customs_sections",
						permission: "ref_customs_sections.view",
					},
					{
						title: m["sidebar.reference_data.customs_warehouses"](),
						url: "/dashboard/reference_data/customs_warehouses",
						permission: "ref_customs_warehouses.view",
					},
					{
						title: m["sidebar.reference_data.incoterms"](),
						url: "/dashboard/reference_data/incoterms",
						permission: "ref_incoterms.view",
					},
					{
						title: m["sidebar.reference_data.document_types_digitization"](),
						url: "/dashboard/reference_data/document_types_digitization",
						permission: "ref_invoice_types.view",
					},
					{
						title: m["sidebar.reference_data.invoice_types"](),
						url: "/dashboard/reference_data/invoice_types",
						permission: "ref_invoice_types.view",
					},
					{
						title: m["sidebar.reference_data.material_types"](),
						url: "/dashboard/reference_data/material_types",
						permission: "ref_material_types.view",
					},
					{
						title: m["sidebar.reference_data.payment_methods"](),
						url: "/dashboard/reference_data/payment_methods",
						permission: "ref_payment_methods.view",
					},
					{
						title: m["sidebar.reference_data.pedimento_codes"](),
						url: "/dashboard/reference_data/pedimento_codes",
						permission: "ref_pedimento_codes.view",
					},
					{
						title: m["sidebar.reference_data.pedimento_regimes"](),
						url: "/dashboard/reference_data/pedimento_regimens",
						permission: "ref_pedimento_regimens.view",
					},
					{
						title: m["sidebar.reference_data.sectors"](),
						url: "/dashboard/reference_data/sectors",
						permission: "ref_sectors.view",
					},
					{
						title: m["sidebar.reference_data.states"](),
						url: "/dashboard/reference_data/states",
						permission: "ref_states.view",
					},
					{
						title: m["sidebar.reference_data.transportation_modes"](),
						url: "/dashboard/reference_data/transport_modes",
						permission: "ref_transport_modes.view",
					},
					{
						title: m["sidebar.reference_data.transportation_types"](),
						url: "/dashboard/reference_data/transport_types",
						permission: "ref_transport_types.view",
					},
					{
						title: m["sidebar.reference_data.valuation_methods"](),
						url: "/dashboard/reference_data/valuation_methods",
						permission: "ref_valuation_methods.view",
					},
				],
				isActive: false,
			},
			{
				title: m["sidebar.general_catalogs.title"](),
				url: "#",
				icon: Package,
				items: [
					{
						title: m["sidebar.general_catalogs.company_information"](),
						url: "/dashboard/general_catalogs/company_information",
						permission: "cat_company.view",
					},
					{
						title: m["sidebar.general_catalogs.packages"](),
						url: "/dashboard/general_catalogs/packages",
						permission: "cat_packages.view",
					},
					{
						title: m["sidebar.general_catalogs.concepts"](),
						url: "/dashboard/general_catalogs/concepts",
						permission: "cat_concepts.view",
					},
					{
						title: m["sidebar.general_catalogs.customs_broker_concepts"](),
						url: "/dashboard/general_catalogs/customs_broker_concepts",
						permission: "cat_broker_concepts.view",
					},
					{
						title: m["sidebar.general_catalogs.classification"](),
						url: "/dashboard/general_catalogs/classification_concepts",
						permission: "cat_classification.view",
					},
					{
						title: m["sidebar.general_catalogs.identifiers"](),
						url: "/dashboard/general_catalogs/identifiers",
						permission: "cat_identifiers.view",
					},
					// -------------------------------------
					{
						title: m["sidebar.general_catalogs.incoterms"](),
						url: "/dashboard/reference_data/incoterms",
						permission: "ref_incoterms.view",
					},
					{
						title: m["sidebar.general_catalogs.inpc"](),
						url: "/dashboard/general_catalogs/inpc",
						permission: "cat_inpc.view",
					},
					{
						title: m["sidebar.general_catalogs.fixed_legends"](),
						url: "/dashboard/general_catalogs/legends",
						permission: "cat_legends.view",
					},
					{
						title: m["sidebar.general_catalogs.seals"](),
						url: "/dashboard/general_catalogs/seal",
						permission: "cat_seals.view",
					},
					{
						title: m["sidebar.general_catalogs.valuation_methods"](),
						url: "/dashboard/reference_data/valuation_methods",
						permission: "ref_valuation_methods.view",
					},
					{
						title: m["sidebar.general_catalogs.countries"](),
						url: "/dashboard/reference_data/countries",
						permission: "ref_countries.view",
					},
					{
						title: m["sidebar.general_catalogs.ports"](),
						url: "/dashboard/general_catalogs/ports",
						permission: "cat_ports.view",
					},
					{
						title: "Ubicaciones",
						url: "/dashboard/general_catalogs/locations",
						permission: "cat_locations.view",
					},
					{
						title: m["sidebar.general_catalogs.unit_measures"](),
						url: "/dashboard/general_catalogs/units_of_measure/general",
						permission: "cat_um_general.view",
					},
					{
						title: m["sidebar.general_catalogs.um_customs_mex"](),
						url: "/dashboard/general_catalogs/units_of_measure/customs",
						permission: "cat_um_customs.view",
					},
					{
						title: m["sidebar.general_catalogs.um_customs_ame"](),
						url: "/dashboard/general_catalogs/units_of_measure/american",
						permission: "cat_um_american.view",
					},
					{
						title: m["sidebar.general_catalogs.um_ace"](),
						url: "/dashboard/general_catalogs/units_of_measure/ace",
						permission: "cat_um_ace.view",
					},
					{
						title: m["sidebar.general_catalogs.um_oma"](),
						url: "/dashboard/general_catalogs/units_of_measure/oma",
						permission: "cat_um_oma.view",
					},
					{
						title: m["sidebar.general_catalogs.conversions"](),
						url: "/dashboard/general_catalogs/unit_conversions",
						permission: "cat_unit_conversions.view",
					},
					{
						title: m["sidebar.general_catalogs.equivalences"](),
						url: "/dashboard/general_catalogs/equivalencies",
						permission: "cat_equivalencies.view",
					},
					{
						title: m["sidebar.general_catalogs.exchange_rates"](),
						url: "/dashboard/general_catalogs/exchange-rate",
						permission: "cat_exchange_rates.view",
					},
					{
						title: m["sidebar.general_catalogs.currency_types"](),
						url: "/dashboard/reference_data/currency_types",
						permission: "ref_currency_types.view",
					},
					{
						title: m["sidebar.general_catalogs.multi_currency"](),
						url: "/dashboard/general_catalogs/multi_currency_types",
						permission: "cat_multi_currency_types.view",
					},
					{
						title: m["sidebar.general_catalogs.invoice_types"](),
						url: "/dashboard/reference_data/invoice_types",
						permission: "ref_invoice_types.view",
					},
					{
						title: m["sidebar.general_catalogs.electronic_signatures"](),
						url: "/dashboard/general_catalogs/signatures",
						permission: "cat_signatures.view",
					},
					{
						title: m["sidebar.general_catalogs.billing_errors"](),
						url: "/dashboard/general_catalogs/error_catalogs",
						permission: "cat_errors.view",
					},
					{
						title: m["sidebar.general_catalogs.customs_warehouses"](),
						url: "/dashboard/reference_data/customs_warehouses",
						permission: "ref_customs_warehouses.view",
					},
					{
						title: m["sidebar.general_catalogs.prevalidators"](),
						url: "/dashboard/general_catalogs/prevalidators",
						permission: "cat_prevalidators.view",
					},
					{
						title: m["sidebar.general_catalogs.electronic_notices"](),
						url: "/dashboard/general_catalogs/electronic_notices",
						permission: "cat_notices.view",
					},
				],
			},
			{
				title: m["sidebar.fractions.title"](),
				url: "#",
				icon: Hash,
				items: [
					{
						title: m["sidebar.fractions.sitar"](),
						url: "/dashboard/general_catalogs/tariff-fractions/sitar",
						permission: 'frac_sitar.view',
					},
					{
						title: m["sidebar.fractions.sitar_seventh_amendment"](),
						url: "/dashboard/general_catalogs/tariff-fractions/seventh-amendment",
						permission: 'frac_sitar_7.view',
					},
					{
						title: m["sidebar.fractions.sitar_us"](),
						url: "/dashboard/general_catalogs/tariff-fractions/us",
						permission: 'frac_sitar_us.view',
					},
					{
						title: m["sidebar.fractions.canadian"](),
						url: "/dashboard/general_catalogs/tariff-fractions/canadian",
						permission: 'frac_canadian.view',
					},
					{
						title: m["sidebar.fractions.historical"](),
						url: "/dashboard/general_catalogs/tariff-fractions/historical",
						permission: 'frac_historical.view',
					},
					{
						title: m["sidebar.fractions.sectors"](),
						url: "/dashboard/general_catalogs/sectors",
						permission: 'ref_sectors.view',
					},
				],
			},
			{
				title: m["sidebar.transports.title"](),
				url: "#",
				icon: Truck,
				items: [
					{
						title: m["sidebar.transports.transporters"](),
						url: "/dashboard/general_catalogs/transporters",
						permission: 'transporters.view',
					},
					{
						title: m["sidebar.transports.drivers"](),
						url: "/dashboard/general_catalogs/drivers",
						permission: 'drivers.view',
					},
					{
						title: m["sidebar.transports.trailers"](),
						url: "/dashboard/general_catalogs/trailers",
						permission: 'trailers.view',
					},
					{
						title: m["sidebar.transports.vehicles"](),
						url: "/dashboard/general_catalogs/vehicles",
						permission: 'vehicles.view',
					},
				],
			},
			{
				title: m["sidebar.goods.title"](),
				url: "#",
				icon: Archive,
				items: [
					{
						title: m["sidebar.goods.classes"](),
						url: "/dashboard/goods/fixed-asset-classes",
						permission: 'goods_classes.view',
					},
					{
						title: m["sidebar.goods.parts"](),
						url: "/dashboard/goods/parts",
						permission: 'goods_parts.view',
					},
					{
						title: m["sidebar.goods.fda_codes"](),
						url: "/dashboard/goods/fda-codes",
					}
				],
			},
			{
				title: m["sidebar.pedimentos.title"](),
				url: "#",
				icon: FileText,
				items: [
					{
						title: m["sidebar.pedimentos.pedimento_management"](),
						url: "/dashboard/pedimentos",
						permission: 'pedimentos_mgmt.view',
					},
					{
						title: m["sidebar.pedimentos.pedimento_codes"](),
						url: "/dashboard/reference_data/pedimento_codes",
						permission: 'ref_pedimento_codes.view',
					},
					{
						title: m["sidebar.pedimentos.customs_regimes"](),
						url: "/dashboard/reference_data/pedimento_regimens",
						permission: 'ref_pedimento_regimens.view',
					},
					{
						title: m["sidebar.pedimentos.payment_methods"](),
						url: "/dashboard/reference_data/payment_methods",
						permission: 'ref_payment_methods.view',
					},
					{
						title: m["sidebar.pedimentos.customs_sections"](),
						url: "/dashboard/reference_data/customs_sections",
						permission: 'ref_customs_sections.view',
					},
					{
						title: m["sidebar.pedimentos.anexo_22_app_31"](),
						url: "#",
					},
				],
			},
			{
				title: m["sidebar.import_invoices.title"](),
				url: "#",
				icon: ArrowDownToLine,
				items: [
					{
						title: m["sidebar.import_invoices.temporary"](),
						url: "/dashboard/invoices?operation_type=imp&invoice_type=TEM",
						permission: "invoice.imp.tem.view"
					},
					{
						title: m["sidebar.import_invoices.definitive"](),
						url: "/dashboard/invoices?operation_type=imp&invoice_type=DEF",
						permission: "invoice.imp.def.view"
					},
					{
						title: m["sidebar.import_invoices.mexican_purchases"](),
						url: "/dashboard/invoices?operation_type=imp&invoice_type=MEX",
						permission: "invoice.imp.cm.view"
					},
					{
						title: m["sidebar.import_invoices.regime_change"](),
						url: "/dashboard/invoices?operation_type=imp&invoice_type=CR",
						permission: "invoice.imp.cr.view"
					},
					{
						title: m["sidebar.import_invoices.repair"](),
						url: "/dashboard/invoices?operation_type=imp&invoice_type=REP",
						permission: "invoice.imp.rep.view"
					}
				],
			},
			{
				title: m["sidebar.export_invoices.title"](),
				url: "#",
				icon: ArrowUpFromLine,
				items: [
					{
						title: m["sidebar.export_invoices.exportation"](),
						url: "/dashboard/invoices?operation_type=exp",
						permission: "invoice.exp.view"
					},
					{
						title: m["sidebar.export_invoices.repair"](),
						url: "/dashboard/invoices?operation_type=exp&invoice_type=REPAR",
						permission: "invoice.exp.rep.view"
					},
				],
			},
			{
				title: m["sidebar.export.title"](),
				url: "#",
				icon: Ship,
				items: [
					{
						title: m["sidebar.export.catalog"](),
						url: "/dashboard/export/catalog",
					},
					{
						title: m["sidebar.export.repair"](),
						url: "/dashboard/export/repair",
					},
					{
						title: m["sidebar.export.manifest"](),
						url: "/dashboard/export/manifest",
					},
					{
						title: m["sidebar.export.proforma"](),
						url: "/dashboard/export/proforma",
					},
					{
						title: m["sidebar.export.reports"](),
						url: "/dashboard/export/reports",
					},
					{
						title: m["sidebar.export.used_materials"](),
						url: "/dashboard/export/used-materials",
					},
					{
						title: m["sidebar.export.destruction"](),
						url: "/dashboard/export/destruction",
					},
					{
						title: m["sidebar.export.special_processes"](),
						url: "/dashboard/export/special-processes",
					},
				],
			},

			{
				title: m["sidebar.clients_and_providers"](),
				url: "/dashboard/clients_and_providers",
				icon: Users,
				permission: "partners_mgmt.view",
				items: [],
			},
			{
				title: m["sidebar.customs_brokers"](),
				url: "/dashboard/customs_brokers",
				icon: BadgeCheck,
				items: [],
			},
			{
				title: m["sidebar.despacho.title"](),
				url: "#",
				icon: GalleryVerticalEnd, // Using a suitable icon
				items: [
					{
						title: m["sidebar.despacho.doda"](),
						url: "/dashboard/despacho/doda",
					},
					{
						title: m["sidebar.despacho.digitalizacion"](),
						url: "/dashboard/despacho/digitalizacion",
					},
				],
			},
			{
				title: m["sidebar.reports.title"](),
				url: "#",
				icon: FileSearch,
				items: [
					{
						title: m["sidebar.reports.invoices"](),
						url: "/dashboard/reports/invoices",
					},
					{
						title: m["sidebar.reports.expiration"](),
						url: "/dashboard/reports/vencimiento",
					},
				],
			},
			{
				title: m["sidebar.reference_data.configuracion"](),
				url: "#",
				icon: Settings2,
				items: [
					{
						title: m["sidebar.reference_data.usuarios"](),
						url: "",
					},
					{
						title: m["sidebar.settings.general"](),
						url: "/dashboard/settings/general",
					},
				],
			},
		],
		projects: [
			{
				name: m["sidebar.reference_data.usuarios"](),
				url: "/dashboard/users",
				icon: Users,
			},
			{
				name: m["sidebar.reference_data.licencia"](),
				url: "#",
				icon: BadgeCheck,
			},
			{
				name: m["sidebar.reference_data.configuracion"](),
				url: "#",
				icon: Settings2,
			},
			{
				name: m["sidebar.help_center"](),
				url: "/dashboard/help-center",
				icon: Book,
			},
		],
	};
}

// Exportar también como constante para compatibilidad (deprecado)
export const sidebarData: SidebarData = getSidebarData();