<script setup>
defineProps({
    categories: {
        type: Array,
        required: true,
    }
});
</script>

<template>
    <section class="bg-gray-100 rounded-md p-4">
        <header class="flex justify-between items-center pb-4">
            <h2 class="text-2xl font-roboto font-light">Kategorie</h2>
            <InertiaLink
                as="button"
                href="/dashboard/category/create"
                class="bg-blue-400 hover:bg-blue-500 text-white px-2.5 py-1 rounded-full"><FontAwesomeIcon :icon="['fas', 'plus']" /></InertiaLink>
        </header>
        <ul class="flex flex-col gap-2">
            <li
                v-for="(category, key) in categories"
                :key="key"
                class="flex items-center justify-between px-3 py-2 bg-white hover:bg-neutral-200"
            >
                <InertiaLink :href="`/dashboard/category/${category.id}`">{{ category.name }}</InertiaLink>
                <div class="flex items-center gap-1">
                    <InertiaLink
                        as="button"
                        class="px-1 py-0.5 text-lime-600 hover:text-lime-800 border-t-2 border-b-2 border-transparent hover:border-b-lime-600"
                        :href="`/dashboard/category/${category.id}`"
                        title="Edytuj kategorię"><FontAwesomeIcon :icon="['fas', 'pen-to-square']" /></InertiaLink>
                    <InertiaLink
                        v-if="!category.default"
                        as="button"
                        class="px-1 py-0.5 text-red-600 hover:text-red-800"
                        :href="`/dashboard/category/${category.id}/delete`"
                        title="Usuń kategorię z listy"><FontAwesomeIcon :icon="['fas', 'trash']" /></InertiaLink>
                </div>
            </li>
        </ul>
    </section>
</template>
