<x-layouts.guest title="Inscription">
    <div class="w-full max-w-md animate-fade-up">
        <div class="mb-8 text-center">
            <x-brand class="justify-center" />
            <h1 class="mt-6 text-2xl font-bold sm:text-3xl">Crée ton compte ✨</h1>
            <p class="mt-2 text-sm" style="color:var(--color-ink-faint)">Rejoins StudyFlash et commence à réviser.</p>
        </div>

        <div class="card card-pad glow" x-data="{ loading: false, show: false }">
            @if ($errors->any())
                <div class="alert alert-danger mb-5" role="alert">
                    <x-icon name="x-circle" :size="18" class="mt-0.5" />
                    <div class="space-y-0.5">
                        @foreach ($errors->all() as $error)
                            <p>{{ $error }}</p>
                        @endforeach
                    </div>
                </div>
            @endif

            <form method="POST" action="{{ route('register') }}" @submit="loading = true" class="space-y-4">
                @csrf
                <div>
                    <label for="name" class="label">Nom d'utilisateur</label>
                    <div class="relative">
                        <span class="pointer-events-none absolute left-3.5 top-1/2 -translate-y-1/2" style="color:var(--color-ink-faint)"><x-icon name="user" :size="18" /></span>
                        <input id="name" name="name" type="text" autocomplete="username" required autofocus minlength="3"
                               value="{{ old('name') }}" placeholder="ton_pseudo" class="field pl-11" />
                    </div>
                </div>

                <div>
                    <label for="email" class="label">Adresse email</label>
                    <div class="relative">
                        <span class="pointer-events-none absolute left-3.5 top-1/2 -translate-y-1/2" style="color:var(--color-ink-faint)"><x-icon name="mail" :size="18" /></span>
                        <input id="email" name="email" type="email" inputmode="email" autocomplete="email" required
                               value="{{ old('email') }}" placeholder="toi@exemple.com" class="field pl-11" />
                    </div>
                </div>

                <div>
                    <label for="password" class="label">Mot de passe</label>
                    <div class="relative">
                        <span class="pointer-events-none absolute left-3.5 top-1/2 -translate-y-1/2" style="color:var(--color-ink-faint)"><x-icon name="lock" :size="18" /></span>
                        <input id="password" name="password" :type="show ? 'text' : 'password'" autocomplete="new-password" required minlength="6"
                               placeholder="6 caractères minimum" class="field px-11" />
                        <button type="button" @click="show = !show" :aria-label="show ? 'Masquer' : 'Afficher'"
                                class="absolute right-2.5 top-1/2 grid h-9 w-9 -translate-y-1/2 place-items-center rounded-lg transition hover:bg-white/5" style="color:var(--color-ink-faint)">
                            <x-icon x-show="!show" name="eye" :size="18" />
                            <x-icon x-show="show" x-cloak name="eye-off" :size="18" />
                        </button>
                    </div>
                </div>

                <div>
                    <label for="password_confirmation" class="label">Confirmer le mot de passe</label>
                    <div class="relative">
                        <span class="pointer-events-none absolute left-3.5 top-1/2 -translate-y-1/2" style="color:var(--color-ink-faint)"><x-icon name="lock" :size="18" /></span>
                        <input id="password_confirmation" name="password_confirmation" :type="show ? 'text' : 'password'" autocomplete="new-password" required
                               placeholder="••••••••" class="field pl-11" />
                    </div>
                </div>

                <button type="submit" class="btn btn-primary btn-lg btn-block" :disabled="loading">
                    <span x-show="!loading" class="inline-flex items-center gap-2">Créer mon compte <x-icon name="sparkles" :size="18" /></span>
                    <span x-show="loading" x-cloak class="inline-flex items-center gap-2">
                        <span class="h-4 w-4 animate-spin-slow rounded-full border-2 border-white/30 border-t-white"></span> Création…
                    </span>
                </button>
            </form>

            <div class="my-5 flex items-center gap-3 text-xs" style="color:var(--color-ink-faint)">
                <span class="h-px flex-1" style="background:var(--color-line)"></span>Déjà inscrit ?<span class="h-px flex-1" style="background:var(--color-line)"></span>
            </div>

            <a href="{{ route('login') }}" class="btn btn-secondary btn-block">Se connecter</a>
        </div>
    </div>
</x-layouts.guest>
