<script setup>
import { computed } from 'vue';

const props = defineProps({
    message: {
        type: Object,
        required: true,
    },
});

const splitMessage = computed(() => props.message.message.split("\n"));
</script>

<template>
    <InertiaHead title="Szczegóły 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/message"
                    class="px-2 text-xl text-gray-700 hover:text-black"
                    title="Wróć do listy wiadomości"><FontAwesomeIcon :icon="['fas', 'caret-left']" /></InertiaLink>
                <h1 class="text-3xl font-roboto font-light">Szczegóły wiadomości</h1>
            </div>
            <div class="flex gap-3 sm:gap-2">
                <InertiaLink
                    as="button"
                    :href="`/dashboard/message/${message.id}/delete`"
                    class="flex items-center gap-2 px-2 py-1 text-red-600 hover:text-white hover:bg-red-600 rounded-md"
                    title="Usuń wiadomość"
                    ><FontAwesomeIcon :icon="['fas', 'trash']" /><span class="hidden sm:inline-block">Usuń</span></InertiaLink>
            </div>
        </header>
        <div class="mb-4">
            <header>
                <h2 class="text-2xl font-roboto font-light pb-3">Podstawowe informacje</h2>
            </header>
            <div class="grid grid-cols-1 md:grid-cols-2 gap-4">
                <div>
                    <div class="text-gray-500 pb-0.5">ID</div>
                    <p class="w-full min-w-full max-w-full px-2.5 py-2 border-b-2 rounded-md bg-white whitespace-nowrap overflow-hidden overflow-ellipsis">{{ message.id }}</p>
                </div>
                <div>
                    <div class="text-gray-500 pb-0.5">Nadawca</div>
                    <p class="w-full min-w-full max-w-full px-2.5 py-2 border-b-2 rounded-md bg-white">{{ message.sender }}</p>
                </div>
                <div>
                    <div class="text-gray-500 pb-0.5">E-mail</div>
                    <p class="w-full min-w-full max-w-full px-2.5 py-2 border-b-2 rounded-md bg-white">{{ message.email }}</p>
                </div>
            </div>
        </div>
        <div class="mb-4">
            <header>
                <h2 class="text-2xl font-roboto font-light pb-3">Treść wiadomości</h2>
            </header>
            <div class="grid grid-cols-1 sm:grid-cols-2 gap-4">
                <div class="col-span-1 sm:col-span-2">
                    <div class="text-gray-500 pb-0.5">Wiadomość</div>
                    <div class="w-full min-w-full max-w-full px-2.5 py-2 border-b-2 rounded-md bg-white">
                        <p
                            v-for="(messageLine, key) in splitMessage"
                            :key="key"
                        >{{ messageLine }}</p>
                    </div>
                </div>
            </div>
        </div>
    </div>
</template>
