<script setup lang="ts">
import MainLayout from "@/Layouts/MainLayout.vue";
import GlassBox from "@/Components/FlightsGoneBy/GlassBox.vue";
import { Head, useForm } from "@inertiajs/vue3";

defineOptions({ layout: MainLayout });

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.store'), {
        onFinish: () => form.reset('password', 'password_confirmation'),
    });
};
</script>

<template>
    <Head title="Reset Password" />
    <GlassBox>
        <h2>Reset Password</h2>
        <p>Choose a new password for your account.</p>

        <v-form style="width: 100%" @submit.prevent="submit">
            <v-container>
                <v-row>
                    <v-col cols="12">
                        <v-text-field
                            v-model="form.email"
                            label="Email"
                            type="email"
                            autocomplete="username"
                            autofocus
                            :error-messages="form.errors.email"
                        />
                    </v-col>
                </v-row>

                <v-row>
                    <v-col cols="12">
                        <v-text-field
                            v-model="form.password"
                            label="Password"
                            type="password"
                            autocomplete="new-password"
                            :error-messages="form.errors.password"
                        />
                    </v-col>
                </v-row>

                <v-row>
                    <v-col cols="12">
                        <v-text-field
                            v-model="form.password_confirmation"
                            label="Confirm Password"
                            type="password"
                            autocomplete="new-password"
                            :error-messages="form.errors.password_confirmation"
                        />
                    </v-col>
                </v-row>

                <v-row>
                    <v-col cols="12" class="d-flex justify-end">
                        <v-btn
                            size="large"
                            type="submit"
                            :loading="form.processing"
                            :disabled="form.processing"
                        >
                            Reset Password
                        </v-btn>
                    </v-col>
                </v-row>
            </v-container>
        </v-form>
    </GlassBox>
</template>

<style scoped>
h2 {
    font-size: 2rem;
    text-align: center;
}

p {
    text-align: center;
    width: 100%;
    opacity: 0.7;
    margin-bottom: 1rem;
}
</style>
