<template>
<Layout title="Log in to your account" description="Enter your email and password below to log in">

    <Head title="Log in" />

    <div v-if="status" class="mb-4 text-center text-sm font-medium text-green-600">
        {{ status }}
    </div>

    <form @submit.prevent="submit" class="d-flex flex-column gap-3">
        <TextInput
            label="Email Address"
            v-model="form.email" />
        <InputError :message="form.errors.email" />

        <TextInput
            label="Password"
            v-model="form.password"
            type="password" />
        <InputError :message="form.errors.password" />



        <div class="flex items-center justify-between">
            <Label for="remember" class="flex items-center space-x-3">
                <Checkbox id="remember" v-model="form.remember" :tabindex="3" />
                <span>Remember me</span>
            </Label>
        </div>

        <Button type="submit" class="mt-4 w-full" :tabindex="4" :disabled="form.processing">
            <LoaderCircle v-if="form.processing" class="h-4 w-4 animate-spin" />
            Log in
        </Button>

        <div class="text-center text-sm text-muted-foreground">
            Don't have an account?
            <TextLink :href="route('register')" :tabindex="5">Sign up</TextLink>
        </div>
    </form>
</Layout>
</template>

<script setup lang="ts">
import InputError from '@/components/InputError.vue';
import TextInput from '@/components/TextInput.vue';
import TextLink from '@/components/TextLink.vue';
import { Button } from '@/components/ui/button';
import { Checkbox } from '@/components/ui/checkbox';
import { Label } from '@/components/ui/label';
import Layout from '@/layouts/AuthLayout.vue';
import { Head, useForm } from '@inertiajs/vue3';
import { LoaderCircle } from 'lucide-vue-next';

defineProps<{
    status?: string;
    canResetPassword: boolean;
}>();

const form = useForm({
    email: '',
    password: '',
    remember: false,
});

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