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

export function createColumns(
    onSuccess: () => void,
    permissions: { canEdit: boolean; canDelete: boolean } = { canEdit: true, canDelete: true }
): ColumnDef<UnitOfMeasureGeneral>[] {
    return [
        {
            accessorKey: 'code',
            header: 'Código',
            cell: (info) => info.getValue()
        },
        {
            accessorKey: 'description',
            header: 'Descripción',
            cell: (info) => info.getValue() || '-'
        },
        {
            id: 'actions',
            header: 'Acciones',
            cell: ({ row }) => {
                return renderComponent(DataTableActions, {
                    unit: row.original,
                    onSuccess,
                    canEdit: permissions.canEdit,
                    canDelete: permissions.canDelete
                });
            }
        }
    ];
}
