<script setup lang="ts">
import AuthenticatedSessionController from '@/actions/App/Http/Controllers/Auth/AuthenticatedSessionController';
import InputError from '@/components/InputError.vue';
import TextLink from '@/components/TextLink.vue';
import { Button } from '@/components/ui/button';
import { Checkbox } from '@/components/ui/checkbox';
import { Input } from '@/components/ui/input';
import { Label } from '@/components/ui/label';
import AuthBase from '@/layouts/AuthLayout.vue';
import { register } from '@/routes';
import { request } from '@/routes/password';
import { Form, Head } from '@inertiajs/vue3';
import { LoaderCircle, Mail } from "lucide-vue-next"

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

</script>

<template>
    <AuthBase title="Caramel CMR" description="Zuckersüße Akquise und butterweiche Kundenpflege">


        <Head title="Log in" />

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

        <Form v-bind="AuthenticatedSessionController.store.form()" :reset-on-success="['password']"
            v-slot="{ errors, processing }" class="flex flex-col gap-6">
            <div class="grid gap-6">
                <div class="grid gap-2">
                    <Label for="email" class="text-stone-300">E-mail Adresse</Label>
                    <div class="relative w-full max-w-sm items-center">
                        <Input id="email" type="email" name="email" required autofocus :tabindex="1"
                            autocomplete="email" placeholder="email@example.com" class="pl-8" />
                        <span class="absolute start-0 inset-y-0 flex items-center justify-center px-2">
                            <Mail class="size-4 text-muted-foreground" />
                        </span>
                    </div>
                    <InputError :message="errors.email" />
                </div>

                <div class="grid gap-2">
                    <div class="flex items-center justify-between">
                        <Label for="password" class="text-stone-300">Passwort</Label>
                        <TextLink v-if="canResetPassword" :href="request()" class="text-sm text-amber-600! decoration-amber-700! hover:text-amber-500!" :tabindex="5"> Passwort
                            vergessen? </TextLink>
                    </div>
                    <Input id="password" type="password" name="password" required :tabindex="2"
                        autocomplete="current-password" placeholder="Passwort" class="" />
                    <InputError :message="errors.password" />
                </div>

                <div class="flex items-center justify-between">
                    <Label for="remember" class="flex items-center space-x-1 text-stone-300">
                        <Checkbox id="remember" name="remember" :tabindex="3" class="" />
                        <span>Meine Session speichern</span>
                    </Label>
                </div>

                <Button :size="sm" :variant="'action'" type="submit" class="mt-4 w-full" :tabindex="4"
                    :disabled="processing" data-test="login-button">
                    <LoaderCircle v-if="processing" class="h-4 w-4 animate-spin" />
                    Anmelden
                </Button>
            </div>

            <div class="text-center text-sm text-muted-foreground">
                <TextLink :href="register()" :tabindex="5" class="text-sm text-amber-600! decoration-amber-700! hover:text-amber-500!">Konto erstellen</TextLink>
            </div>
        </Form>
    </AuthBase>
</template>
