import type { Company } from '$lib/api/dashboard/a76/general_catalogs/company';
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 }): ColumnDef<Company>[] {
    return [
        {
            accessorKey: 'name',
            header: 'Nombre',
            cell: ({ row }) => row.original.name || '-'
        },
        {
            accessorKey: 'rfc',
            header: 'RFC',
            cell: ({ row }) => row.original.rfc || '-'
        },
        {
            accessorKey: 'program',
            header: 'Programa',
            cell: ({ row }) => row.original.program || '-'
        },
        {
            accessorKey: 'program_number',
            header: 'No. Programa',
            cell: ({ row }) => row.original.program_number || '-'
        },
        {
            id: 'actions',
            cell: ({ row }) => {
                return renderComponent(DataTableActions, {
                    item: row.original,
                    onSuccess,
                    canEdit: permissions?.canEdit,
                    canDelete: permissions?.canDelete
                });
            }
        }
    ];
}
