<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>

        <div class="mt-6 border border-slate-200 mb-16 ">
            <div class="grid grid-cols-2 gap-4 bg-slate-100 px-4 py-3 text-sm font-semibold uppercase tracking-wide">
                <div>Label</div>
                <div>Code</div>
            </div>
            <div
                v-for="carrier in carrierList"
                :key="carrier.id"
                class="grid grid-cols-2 gap-4 px-4 py-3 text-sm hover:bg-slate-50 cursor-pointer border-t border-slate-200"
                role="button"
                tabindex="0"
                @click="goToCarrier(carrier.id)"
                @keydown.enter="goToCarrier(carrier.id)"
            >
                <div>{{ carrier.name}}</div>
                <div>{{ carrier.code }}</div>
            </div>
        </div>

</template>

<script setup lang="ts">
import type {CarrierData} from "~/services/dto/carrier-data";
import {getCarrierList} from "~/services/carrier";

const carrierList = ref<CarrierData[]>()
const router = useRouter()

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

definePageMeta({
    layout: 'default'
})

onMounted(async () => {
    carrierList.value = await getCarrierList(false)
})
</script>
