<script setup>
import { ref } from "vue";
import { Head, useForm } from "@inertiajs/inertia-vue3";
import JetAuthenticationCard from "@/Jetstream/AuthenticationCard.vue";
import JetAuthenticationCardLogo from "@/Jetstream/AuthenticationCardLogo.vue";
import JetButton from "@/Jetstream/Button.vue";
import JetInput from "@/Jetstream/Input.vue";
import JetLabel from "@/Jetstream/Label.vue";
import JetValidationErrors from "@/Jetstream/ValidationErrors.vue";
import Layout from "@/Layouts/PromoSidebar";

const form = useForm({
    password: "",
});

const passwordInput = ref(null);

const submit = () => {
    form.post(route("password.confirm"), {
        onFinish: () => {
            form.reset();

            passwordInput.value.focus();
        },
    });
};
</script>

<template>
    <Layout title="Secure Area">
        <div
            class="container flex flex-col items-center justify-center flex-1 py-5"
        >
            <JetAuthenticationCard>
                <template #logo>
                    <JetAuthenticationCardLogo />
                </template>

                <div class="mb-4 text-sm text-gray-600">
                    This is a secure area of the application. Please confirm
                    your password before continuing.
                </div>

                <JetValidationErrors class="mb-4" />

                <form @submit.prevent="submit">
                    <div>
                        <JetLabel for="password" value="Password" />
                        <JetInput
                            id="password"
                            ref="passwordInput"
                            v-model="form.password"
                            autocomplete="current-password"
                            autofocus
                            class="block w-full mt-1"
                            required
                            type="password"
                        />
                    </div>

                    <div class="flex justify-end mt-4">
                        <JetButton
                            @click="submit"
                            :class="{ 'opacity-25': form.processing }"
                            :disabled="form.processing"
                            class="ml-4"
                        >
                            Confirm
                        </JetButton>
                    </div>
                </form>
            </JetAuthenticationCard>
        </div>
    </Layout>
</template>
