<script setup>
import { useForm } from '@inertiajs/inertia-vue3';
import Input from '../../Share/Components/Input.vue';

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

const form = useForm({
    title: props.note.title,
    note: props.note.note,
});

function updateNote() {
    form.put(`/dashboard/note/${props.note.id}`);
}
</script>

<template>
    <InertiaHead title="Edycja notatki" />
    <div class="p-4">
        <header class="flex items-center justify-between pb-4">
            <div class="flex items-center gap-2">
                <InertiaLink
                    as="button"
                    :href="`/dashboard/note/${note.id}`"
                    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">Edycja notatki</h1>
            </div>
            <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']" />Usuń</InertiaLink>
        </header>
        <div>
            <form class="flex flex-col gap-4" @submit.prevent="updateNote">
                <Input
                    id="title"
                    label="Tytuł notatki"
                    placeholder="np. Witaj świecie!"
                    v-model="form.title"
                    :error="form.errors.title"
                />
                <Input
                    id="note"
                    type="textarea"
                    label="Treść notatki"
                    placeholder="Treść"
                    v-model="form.note"
                    :error="form.errors.note"
                />
                <div class="grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 gap-3 sm:gap-2 items-center">
                    <InertiaLink
                        as="button"
                        :href="`/dashboard/note/${note.id}`"
                        class="col-span-1 flex justify-center items-center gap-3 w-full px-2 py-1 border-t-4 border-b-4 border-transparent hover:border-b-black"
                        ><FontAwesomeIcon :icon="['fas', 'backward']" />Anuluj</InertiaLink>
                    <button class="col-span-1 md:col-span-2 px-0.5 py-1 rounded-lg bg-[#436da7] border-4 border-[#436da7] text-white text-lg hover:bg-transparent hover:text-[#436da7]">Edytuj notatkę</button>
                </div>
            </form>
        </div>
    </div>
</template>
