import type { ColumnDef } from "@tanstack/table-core";
import type { UnitOfMeasureAmerican } from "$lib/api/dashboard/a76/general_catalogs/units-of-measure";
import { renderComponent } from "$lib/components/ui/data-table/index.js";
import DataTableActions from "./data-table-actions.svelte";

export function createColumns(
    onSuccess: () => void,
    permissions: { canEdit: boolean; canDelete: boolean } = { canEdit: true, canDelete: true }
): ColumnDef<UnitOfMeasureAmerican>[] {
    return [
        {
            accessorKey: "code",
            header: "Código",
        },
        {
            accessorKey: "description",
            header: "Descripción",
        },
        {
            id: "actions",
            header: "Acciones",
            cell: ({ row }) => {
                return renderComponent(DataTableActions, {
                    unit: row.original,
                    onSuccess,
                    canEdit: permissions.canEdit,
                    canDelete: permissions.canDelete
                });
            },
        },
    ];
}
