/**
 * Definición de columnas para la tabla de Vehículos
 */
import type { Vehicle } from '$lib/api/dashboard/a76/vehicles';
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): ColumnDef<Vehicle>[] {
    return [
        {
            accessorKey: 'vehicle_key',
            header: 'Clave',
            cell: ({ row }) => {
                return row.original.vehicle_key;
            }
        },
        {
            accessorKey: 'brand',
            header: 'Marca',
            cell: ({ row }) => {
                return row.original.brand || '-';
            }
        },
        {
            accessorKey: 'year',
            header: 'Año',
            cell: ({ row }) => {
                return row.original.year || '-';
            }
        },
        {
            accessorKey: 'plate_number',
            header: 'Placas',
            cell: ({ row }) => {
                return row.original.plate_number || '-';
            }
        },
        {
            accessorKey: 'transporter_key',
            header: 'Transportista',
            cell: ({ row }) => {
                return row.original.transporter_key || '-';
            }
        },
        {
            accessorKey: 'transport_type',
            header: 'Tipo Transporte',
            cell: ({ row }) => {
                return row.original.transport_type || '-';
            }
        },
        {
            id: 'actions',
            header: 'Acciones',
            cell: ({ row }) => {
                return renderComponent(DataTableActions, {
                    item: row.original,
                    onSuccess
                });
            }
        }
    ];
}
