<template>

    <div class="flex items-center justify-between ">
            <h1 class="text-3xl font-bold uppercase text-primary-500">listes des transporteurs</h1>
    </div>

        <div class="mt-7 border border-slate-200 mb-11 ">
            <div class="grid grid-cols-2 gap-4 text-primary-700 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 text-primary-700 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>
    <div class="flex justify-center items-center">
        <NuxtLink
            to="/admin/carrier"
            class="inline-flex items-center justify-center text-xl text-white uppercase bg-primary-500 h-[50px] px-8 rounded hover:opacity-80 gap-2"
        >
            <Icon name="mdi:plus" size="28"  />
            Ajouter
        </NuxtLink>
    </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}`)
}

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