import type { Sector } from '$lib/api/dashboard/general_catalogs/sectors';
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<Sector>[] {
    return [
        {
            accessorKey: 'key',
            header: 'Clave',
            cell: ({ row }) => row.original.key || '-'
        },
        {
            accessorKey: 'description',
            header: 'Descripción',
            cell: ({ row }) => row.original.description || '-'
        },
        {
            accessorKey: 'authorized',
            header: 'Estatus',
            cell: ({ row }) => (row.original.authorized ? 'Autorizado' : 'No Autorizado')
        },
        {
            id: 'actions',
            header: '',
            cell: ({ row }) =>
                renderComponent(DataTableActions, {
                    item: row.original,
                    onSuccess,
                    canEdit: permissions?.canEdit ?? false,
                    canDelete: permissions?.canDelete ?? false
                })
        }
    ];
}
