import type { ColumnDef } from '@tanstack/table-core';
import type { Location } from '$lib/api/dashboard/a76/general_catalogs/locations';
import { renderComponent } from '$lib/components/ui/data-table';
import DataTableActions from './data-table-actions.svelte';

const SYSTEM_LABELS: Record<string, string> = {
	fixed_asset: 'Activo fijo (FA)',
	inventory: 'Inventario'
};

export function createColumns(
	onSuccess?: () => void,
	options: { canEdit?: boolean; canDelete?: boolean } = {}
): ColumnDef<Location>[] {
	const { canEdit = true, canDelete = true } = options;
	return [
		{
			accessorKey: 'clave_localizacion',
			header: 'Clave'
		},
		{
			accessorKey: 'localizacion',
			header: 'Localización',
			cell: ({ row }) => row.original.localizacion ?? '—'
		},
		{
			accessorKey: 'system',
			header: 'Sistema',
			cell: ({ row }) => SYSTEM_LABELS[row.original.system] ?? row.original.system
		},
		{
			id: 'actions',
			header: 'Acciones',
			cell: ({ row }) =>
				renderComponent(DataTableActions, {
					item: row.original,
					onSuccess,
					canEdit,
					canDelete
				})
		}
	];
}
