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

export function createColumns(
    onSuccess?: () => void,
    { canEdit = true, canDelete = true }: { canEdit?: boolean; canDelete?: boolean } = {}
): ColumnDef<ErrorCatalog>[] {
    return [
        {
            accessorKey: 'code',
            header: 'Código'
        },
        {
            accessorKey: 'description',
            header: 'Descripción',
            cell: ({ row }) => row.original.description ?? '—'
        },
        {
            accessorKey: 'classification_id',
            header: 'Clasificación',
            cell: ({ row }) => row.original.classification_id ?? '—'
        },
        {
            id: 'actions',
            header: 'Acciones',
            cell: ({ row }) => renderComponent(DataTableActions, {
                item: row.original,
                onSuccess,
                canEdit,
                canDelete
            })
        }
    ];
}
