<script setup>
import EmptyState from '@/Share/Components/EmptyState.vue';

defineProps({
    messages: {
        type: Object,
        default: {},
    },
});
</script>

<template>
    <InertiaHead title="Wiadomości" />
    <div class="p-4">
        <header class="flex justify-between items-center pb-4">
            <div class="flex items-center gap-2">
                <InertiaLink
                    as="button"
                    href="/dashboard"
                    class="px-2 text-xl text-gray-700 hover:text-black"
                    title="Wróc do dashboard"><FontAwesomeIcon :icon="['fas', 'caret-left']" /></InertiaLink>
                <h1 class="text-3xl font-roboto font-light">Wiadomości</h1>
            </div>
        </header>
        <div class="overflow-x-auto">
            <table v-if="messages.data.length" class="table-fixed w-full min-w-[600px] border-separate border-spacing-y-2 cursor-pointer">
                <colgroup>
                    <col class="w-[40px] max-w-[60px]" />
                    <col class="w-[250px]" />
                    <col class="w-auto" />
                    <col class="w-[50px]" />
                </colgroup>
                <thead class="text-left bg-gray-100">
                    <th class="w-[40px] max-w-[60px] p-2 text-center">ID</th>
                    <th class="w-[250px] p-2">Wysyłający</th>
                    <th class="p-2">E-mail</th>
                    <th class="w-[50px] p-2"></th>
                </thead>
                <tbody>
                    <InertiaLink
                        as="tr"
                        v-for="(message, key) in messages.data"
                        :key="key"
                        class="px-3 py-2 bg-white hover:bg-neutral-200 rounded-md z-10"
                        :href="`/dashboard/message/${message.id}`">
                        <td class="p-2 w-[60px] text-center">#{{ message.id }}</td>
                        <td class="p-2 whitespace-nowrap overflow-hidden overflow-ellipsis">{{ message.sender }}</td>
                        <td class="p-2">{{ message.email }}</td>
                        <td class="flex items-center justify-end gap-2 p-3 z-50">
                            <InertiaLink
                                as="button"
                                class="px-3 py-3 text-red-600 hover:text-red-800"
                                :href="`/dashboard/message/${message.id}/delete`"
                                title="Usuń wiadomość z listy"><FontAwesomeIcon :icon="['fas', 'trash']" /></InertiaLink>
                        </td>
                    </InertiaLink>
                </tbody>
            </table>
            <EmptyState v-else :icon="['fas', 'message']">
                <template #title>Brak wiadomości</template>
                <template #text>Nie przesłano jeszcze żadnej wiadomości.</template>
            </EmptyState>
        </div>
    </div>
</template>
