<script setup>
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 props = defineProps({
    email: String,
    token: String,
});

const form = useForm({
    token: props.token,
    email: props.email,
    password: "",
    password_confirmation: "",
});

const submit = () => {
    form.post(route("password.update"), {
        onFinish: () => form.reset("password", "password_confirmation"),
    });
};
</script>

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

                <JetValidationErrors class="mb-4" />

                <form @submit.prevent="submit">
                    <div>
                        <JetLabel for="email" value="Email" />
                        <JetInput
                            id="email"
                            v-model="form.email"
                            autofocus
                            class="block w-full mt-1"
                            required
                            type="email"
                        />
                    </div>

                    <div class="mt-4">
                        <JetLabel for="password" value="Password" />
                        <JetInput
                            id="password"
                            v-model="form.password"
                            autocomplete="new-password"
                            class="block w-full mt-1"
                            required
                            type="password"
                        />
                    </div>

                    <div class="mt-4">
                        <JetLabel
                            for="password_confirmation"
                            value="Confirm Password"
                        />
                        <JetInput
                            id="password_confirmation"
                            v-model="form.password_confirmation"
                            autocomplete="new-password"
                            class="block w-full mt-1"
                            required
                            type="password"
                        />
                    </div>

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