import type { Concept } from '$lib/api/dashboard/a76/general_catalogs/concepts';
import type { ColumnDef } from '@tanstack/table-core';
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<Concept>[] {
    return [
        {
            accessorKey: 'code',
            header: 'Código',
            cell: ({ row }) => row.original.code || '-'
        },
        {
            accessorKey: 'description',
            header: 'Descripción',
            cell: ({ row }) => row.original.description || '-'
        },
        {
            accessorKey: 'type',
            header: 'Tipo',
            cell: ({ row }) => row.original.type || '-'
        },
        {
            accessorKey: 'section',
            header: 'Sección',
            cell: ({ row }) => row.original.section?.toString() || '-'
        },
        {
            id: 'actions',
            header: 'Acciones',
            cell: ({ row }) => {
                return renderComponent(DataTableActions, {
                    item: row.original,
                    onSuccess,
                    canEdit: permissions.canEdit,
                    canDelete: permissions.canDelete
                });
            }
        }
    ];
}
