<script setup lang="ts">
import LayoutAuthenticated from '@/Layouts/LayoutAuthenticated.vue';
import SectionMain from '@/Components/SectionMain.vue';
import SectionTitleLineWithButton from '@/Components/SectionTitleLineWithButton.vue';
import { useForm, Head, usePage } from '@inertiajs/vue3';
import { computed, Ref } from 'vue';
import CardBox from '@/Components/CardBox.vue';
import BaseButton from '@/Components/BaseButton.vue';
import BaseButtons from '@/Components/BaseButtons.vue';
import { stardust } from '@eidellev/adonis-stardust/client';
import { mdiArrowLeftBoldOutline, mdiDeleteForever, mdiTrashCan } from '@mdi/js';
import FormValidationErrors from '@/Components/FormValidationErrors.vue';

const props = defineProps({
    mimetype: {
        type: Object,
        default: () => ({}),
    },
});
const flash: Ref<any> = computed(() => {
    return usePage().props.flash;
});
const errors: Ref<any> = computed(() => {
    return usePage().props.errors;
});
const form = useForm({
    preferred_reviewer: '',
    preferred_reviewer_email: '',
    preferation: 'yes_preferation',

    // preferation: '',
    // isPreferationRequired: false,
});

const handleSubmit = async (e: Event) => {
    e.preventDefault();
    await form.delete(stardust.route('settings.mimetype.deleteStore', [props.mimetype.id]));
};
</script>

<template>
    <LayoutAuthenticated>
        <Head title="Delete mimetype" />
        <SectionMain>
            <SectionTitleLineWithButton :icon="mdiDeleteForever" title="Delete Mimetype" main>
                <BaseButton :route-name="stardust.route('settings.mimetype.index')" :icon="mdiArrowLeftBoldOutline" label="Back"
                    color="white" rounded-full small />
            </SectionTitleLineWithButton>
            <CardBox form @submit.prevent="handleSubmit">
                <FormValidationErrors v-bind:errors="errors" />
                <div class="modal-content py-4 text-left px-6">
                    <div class="text-xl font-bold mb-4">Confirm Deletion</div>
                    <p>Are you sure you want to delete the mimetype?</p>
                    <ul class="mt-4 space-y-4 text-left text-gray-500 dark:text-gray-400">
                        <li class="flex items-center space-x-3">
                            <svg class="flex-shrink-0 w-3.5 h-3.5 text-green-500 dark:text-green-400" aria-hidden="true"
                                xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 16 12">
                                <path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
                                    d="M1 5.917 5.724 10.5 15 1.5" />
                            </svg>
                            <span>{{ props.mimetype.name }} ({{ props.mimetype.file_extension }})</span>
                        </li>
                    </ul>
                </div>
                <div v-if="flash && flash.warning" class="flex flex-col mt-6 animate-fade-in">
                    <div class="bg-yellow-500 border-l-4 border-orange-400 text-white p-4" role="alert">
                        <p class="font-bold">Be Warned</p>
                        <p>{{ flash.warning }}</p>
                    </div>
                </div>
                <template #footer>
                    <BaseButtons>
                        <BaseButton type="submit" color="danger" :icon="mdiTrashCan" :small="true"
                            :class="{ 'opacity-25': form.processing }" :disabled="form.processing" label="Confirm Delete" />
                    </BaseButtons>
                </template>
            </CardBox>
        </SectionMain>
    </LayoutAuthenticated>
</template>
