<template>

    <div class="flex items-center justify-between ">
            <h1 class="text-3xl font-bold uppercase">listes des transporteurs</h1>
            <button
                @Click="router.push(`/admin/carrier/add-carrier`)"
                class="text-xl uppercase bg-primary-500 text-white h-[50px] w-[272px] justify-self-end"
            >Ajouter
            </button>
    </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: 'admin'
})

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