import type { ColumnDef } from '@tanstack/table-core';
import type { Equivalency } from '$lib/api/dashboard/a76/general_catalogs/equivalencies';
import { renderComponent } from '$lib/components/ui/data-table';
import CatalogDataTableActions from './catalog-data-table-actions.svelte';

export function createCatalogColumns({
	onInsertItems,
	onEdit,
	onSuccess,
	canEdit = true,
	canDelete = true
}: {
	onInsertItems: (equivalency: Equivalency) => void;
	onEdit: (equivalency: Equivalency) => void;
	onSuccess?: () => void;
	canEdit?: boolean;
	canDelete?: boolean;
}): ColumnDef<Equivalency>[] {
	return [
		{
			accessorKey: 'identifier',
			header: 'Identificador',
			cell: ({ row }) => row.original.identifier || 'N/A'
		},
		{
			accessorKey: 'description',
			header: 'Descripción',
			cell: ({ row }) => row.original.description || ''
		},
		{
			id: 'actions',
			header: 'Acciones',
			cell: ({ row }) => {
				return renderComponent(CatalogDataTableActions, {
					item: row.original,
					onInsertItems,
					onEdit,
					onSuccess,
					canEdit,
					canDelete
				});
			}
		}
	];
}

