import type { Identifier } from '$lib/api/dashboard/a76/general_catalogs/identifiers';
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): ColumnDef<Identifier>[] {
    return [
        {
            accessorKey: 'code',
            header: 'Clave',
        },
        {
            accessorKey: 'description',
            header: 'Descripción',
            cell: ({ row }) => row.original.description || '-'
        },
        {
            accessorKey: 'level',
            header: 'Nivel',
            cell: ({ row }) => row.original.level || '-'
        },
        {
            accessorKey: 'complement',
            header: 'Complemento',
            cell: ({ row }) => row.original.complement || '-'
        },
        {
            id: 'actions',
            header: 'Acciones',
            cell: ({ row }) => {
                return renderComponent(DataTableActions, {
                    item: row.original,
                    onSuccess
                });
            }
        }
    ];
}
