/**
 * Definición de columnas para la tabla de Packages
 */
import type { Package } from '$lib/api/dashboard/a76/general_catalogs/packages';
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<Package>[] {
	return [
	{
		accessorKey: 'key',
		header: 'Clave',
		cell: ({ row }) => {
			return row.original.key;
		}
	},
	{
		accessorKey: 'description_es',
		header: 'Descripción (ES)',
		cell: ({ row }) => {
			return row.original.description_es || '-';
		}
	},
	{
		accessorKey: 'description_en',
		header: 'Descripción (EN)',
		cell: ({ row }) => {
			return row.original.description_en || '-';
		}
	},
	{
		accessorKey: 'weight_unit',
		header: 'Peso Unitario',
		cell: ({ row }) => {
			return row.original.weight_unit ? row.original.weight_unit.toString() : '-';
		}
	},
	{
		accessorKey: 'plurals',
		header: 'Plural',
		cell: ({ row }) => {
			return row.original.plurals || '-';
		}
	},
	{
		accessorKey: 'code_ace',
		header: 'Código ACE',
		cell: ({ row }) => {
			return row.original.code_ace || '-';
		}
	},
	{
		accessorKey: 'code_aamex',
		header: 'Código AAMEX',
		cell: ({ row }) => {
			return row.original.code_aamex || '-';
		}
	},
	{
		id: 'actions',
		header: 'Acciones',
		cell: ({ row }) => {
			return renderComponent(DataTableActions, {
				item: row.original,
				onSuccess,
				canEdit: permissions.canEdit,
				canDelete: permissions.canDelete
			});
		}
	}
	];
}
