<template>
    <div class="flex items-center justify-between ">
        <h1 class="text-3xl font-bold uppercase text-primary-500">listes des transporteurs</h1>
        <NuxtLink
            to="/admin/carrier"
            class="inline-flex items-center justify-center gap-2 text-xl uppercase bg-primary-500 text-white h-[50px] px-8 rounded"
        >
            <Icon name="mdi:plus" size="28"/>
            Ajouter
        </NuxtLink>
    </div>

    <UiDataTable
        :columns="columns"
        url="carriers"
        @row-click="onCarrierRowClick"
    />
</template>

<script setup lang="ts">
import type {ColumnConfig, Row} from "~/services/dto/datatable-data";

const router = useRouter()

const columns: ColumnConfig[] = [
    {key: "name", label: "Label"},
    {key: "code", label: "Code"},
]

const goToCarrier = (id: number) => {
    router.push(`/admin/carrier/${id}`)
}

const onCarrierRowClick = (row: Row) => {
    const id = Number(row.id)
    if (!Number.isFinite(id)) return
        goToCarrier(id)
}

definePageMeta({
    layout: 'default'
})
</script>
