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

export function createColumns(
    onSuccess: () => void,
    permissions: { canEdit: boolean; canDelete: boolean } = { canEdit: true, canDelete: true }
): ColumnDef<Identifier>[] {
    return [
        {
            accessorKey: 'code',
            header: 'Clave',
            cell: ({ row }) => row.original.code || 'N/A'
        },
        {
            accessorKey: 'description',
            header: 'Descripción',
            cell: ({ row }) => row.original.description || 'N/A'
        },
        {
            accessorKey: 'level',
            header: 'Nivel',
            cell: ({ row }) => row.original.level || 'N/A'
        },
        {
            accessorKey: 'complement',
            header: 'Complemento',
            cell: ({ row }) => row.original.complement || 'N/A'
        },
        {
            id: 'actions',
            header: 'Acciones',
            cell: ({ row }) => {
                return renderComponent(DataTableActions, {
                    item: row.original,
                    onSuccess,
                    canEdit: permissions.canEdit,
                    canDelete: permissions.canDelete
                });
            }
        }
    ];
}
