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

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

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

<template>
    <InertiaHead title="Szczegóły notatki" />
    <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/note"
                    class="px-2 text-xl text-gray-700 hover:text-black"
                    title="Wróć do listy notatek"><FontAwesomeIcon :icon="['fas', 'caret-left']" /></InertiaLink>
                <h1 class="text-3xl font-roboto font-light">Szczegóły notatki</h1>
            </div>
            <div class="flex gap-3 sm:gap-2">
                <InertiaLink
                    as="button"
                    :href="`/dashboard/note/${note.id}/edit`"
                    class="flex items-center gap-2 px-2 py-1 text-lime-600 hover:text-white hover:bg-lime-600 rounded-md"
                    title="Edytuj notatkę"
                    ><FontAwesomeIcon :icon="['fas', 'pen-to-square']" /><span class="hidden sm:inline-block">Edytuj</span></InertiaLink>
                <InertiaLink
                    as="button"
                    :href="`/dashboard/note/${note.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ń notatkę"
                    ><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="flex flex-col gap-4">
                <div>
                    <div class="text-gray-500 pb-0.5">Tytuł</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"
                    >{{ note.title }}</p>
                </div>
                <div class="md:col-span-2">
                    <div class="text-gray-500 pb-0.5">Notatka</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="(noteLine, key) in noteLines"
                            :key="key"
                        >{{ noteLine }}</p>
                    </div>
                </div>
            </div>
        </div>
    </div>
</template>
