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

export const createColumns = (
    onSuccess: () => void,
    permissions: { canEdit: boolean; canDelete: boolean } = { canEdit: true, canDelete: true }
): ColumnDef<Legend>[] => [
    {
        accessorKey: 'code',
        header: 'Código',
        cell: ({ row }) => row.original.code?.toString() || '-'
    },
    {
        accessorKey: 'description',
        header: 'Descripción',
        cell: ({ row }) => row.original.description || '-'
    },
    {
        id: 'actions',
        header: 'Acciones',
        cell: ({ row }) => {
            return renderComponent(DataTableActions, {
                item: row.original,
                onSuccess,
                canEdit: permissions.canEdit,
                canDelete: permissions.canDelete
            });
        }
    }
];
