import type { CustomsBrokerConcept } from '$lib/api/dashboard/a76/general_catalogs/customs-broker-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<CustomsBrokerConcept>[] {
    return [
        {
            accessorKey: 'broker_key',
            header: 'Clave Agente',
            cell: ({ row }) => row.original.broker_key || '-'
        },
        {
            accessorKey: 'concept',
            header: 'Concepto',
            cell: ({ row }) => row.original.concept || '-'
        },
        {
            accessorKey: 'amount',
            header: 'Importe',
            cell: ({ row }) => row.original.amount ? `$${Number(row.original.amount).toFixed(2)}` : '-'
        },
        {
            accessorKey: 'priority',
            header: 'Prioridad',
            cell: ({ row }) => row.original.priority?.toString() || '-'
        },
        {
            id: 'actions',
            header: 'Acciones',
            cell: ({ row }) => {
                return renderComponent(DataTableActions, {
                    item: row.original,
                    onSuccess,
                    canEdit: permissions.canEdit,
                    canDelete: permissions.canDelete
                });
            }
        }
    ];
}
