<template>
    <div class="flex items-center justify-between">
        <div class="flex items-center gap-10">
            <Icon @click="router.push('/')" name="gg:arrow-left-o" size="44" class="cursor-pointer text-primary-500"/>
            <h1 class="text-3xl font-bold uppercase text-primary-500">listes des expéditions en attente</h1>
        </div>
    </div>
    <UiDataTable
        :columns="columns"
        url="shipments"
        :query="{ isValid: false }"
        @row-click="goToShipment"
    />
</template>

<script setup lang="ts">
import {formatBovinShipments} from "~/utils/datatable-formatters";

const router = useRouter()

const columns = [
    {key: 'customer.name', label: 'Client', isSearchable:true},
    {key: 'address.fullAddress', label: 'Adresse', isSearchable:true},
    {key: 'carrier.name', label: 'Transporteur', isSearchable:true},
    {key: 'bovinShipments', label: 'Type', format:formatBovinShipments},
    {key: 'licencePlate', label: 'Immatriculation', isSearchable:true},
]

type ReceptionRow = {
    id?: number | string
}

const goToShipment = (row: ReceptionRow) => {
    const id = Number(row?.id)
    if (!Number.isFinite(id)) return
    router.push(`/shipment/${id}`)
}
</script>
