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

defineOptions({ layout: MainLayout });

const form = useForm({
    name: '',
    email: '',
    password: '',
    password_confirmation: '',
});

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

<template>
    <Head title="Register" />
    <GlassBox title="Create Account" blurb="Start logging your flights today.">
        <v-form style="width: 100%" @submit.prevent="submit">
            <v-container>
                <v-row>
                    <v-col cols="12">
                        <v-text-field
                            v-model="form.name"
                            label="Username"
                            autocomplete="username"
                            autofocus
                            :error-messages="form.errors.name"
                        />
                    </v-col>
                </v-row>

                <v-row>
                    <v-col cols="12">
                        <v-text-field
                            v-model="form.email"
                            label="Email"
                            type="email"
                            autocomplete="username"
                            :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 align-center justify-end" style="gap: 1rem">
                        <v-btn
                            variant="elevated"
                            size="large"
                            block
                            type="submit"
                            :loading="form.processing"
                            :disabled="form.processing"
                        >
                            Register
                        </v-btn>
                    </v-col>
                </v-row>
                <v-row>
                    <v-col cols="12" class="d-flex align-center justify-end" style="gap: 1rem">
                        <Link :href="route('login')" style="opacity: 0.7; font-size: 0.9rem">
                            Already registered?
                        </Link>
                    </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>
