@extends('layouts.nova')

@section('content')
<div class="flex-1 flex items-center justify-center px-6 py-16 min-h-[calc(100vh-4rem)] box-border">
    <div class="max-w-5xl w-full">
        <div class="rounded-2xl border border-white/10 bg-slate-900/70 backdrop-blur shadow-xl p-8 auth-card">
            <h2 class="text-2xl font-semibold mb-2 text-white">Login</h2>

            <p class="text-sm text-white/60 mb-6">Access your Skinbase account.</p>

            @include('auth.partials.help-links', [
                'title' => 'Need help signing in?',
                'description' => 'Use the signup and login guide or the troubleshooting page before spending time guessing at the wrong fix.',
                'showReset' => true,
            ])

            <x-auth-session-status class="mt-4 mb-2 text-green-300" :status="session('status')" />

            @if($errors->has('oauth'))
                <div class="rounded-lg bg-red-900/40 border border-red-500/40 px-4 py-3 text-sm text-red-300 mb-4">
                    {{ $errors->first('oauth') }}
                </div>
            @endif

            @if($errors->has('bot'))
                <div class="rounded-lg bg-red-900/40 border border-red-500/40 px-4 py-3 text-sm text-red-300 mb-4">
                    {{ $errors->first('bot') }}
                </div>
            @endif

            @include('auth.partials.social-login')

            <form method="POST" action="{{ route('login') }}" class="space-y-5" data-bot-form>
                @csrf
                <input type="text" name="homepage_url" value="" tabindex="-1" autocomplete="off" class="hidden" aria-hidden="true">
                <input type="hidden" name="_bot_fingerprint" value="">

                @php
                    $captchaProvider = $captcha['provider'] ?? 'turnstile';
                    $captchaSiteKey = $captcha['siteKey'] ?? '';
                @endphp

                <div>
                    <label class="block text-sm mb-1 text-white/80" for="email">Email or legacy username</label>
                    <input id="email" name="email" type="text" required placeholder="you@example.com or legacy username" value="{{ old('email') }}" class="w-full rounded-lg bg-slate-950/70 border border-white/10 px-4 py-3 text-sm focus:outline-none focus:ring-2 focus:ring-purple-500 text-white" />
                    <p class="mt-2 text-xs text-white/50">Username sign-in is only available for older accounts that still need to add a real email address.</p>
                    <x-input-error :messages="$errors->get('email')" class="mt-2" />
                </div>

                <div>
                    <label class="block text-sm mb-1 text-white/80" for="password">Password</label>
                    <input id="password" name="password" type="password" required placeholder="••••••••••" class="w-full rounded-lg bg-slate-950/70 border border-white/10 px-4 py-3 text-sm focus:outline-none focus:ring-2 focus:ring-purple-500 text-white" />
                    <x-input-error :messages="$errors->get('password')" class="mt-2" />
                </div>

                @if(($requiresCaptcha ?? false) && $captchaSiteKey !== '')
                    @if($captchaProvider === 'recaptcha')
                        <div class="g-recaptcha" data-sitekey="{{ $captchaSiteKey }}" data-theme="dark"></div>
                    @elseif($captchaProvider === 'hcaptcha')
                        <div class="h-captcha" data-sitekey="{{ $captchaSiteKey }}" data-theme="dark"></div>
                    @else
                        <div class="cf-turnstile" data-sitekey="{{ $captchaSiteKey }}" data-theme="dark"></div>
                    @endif
                    <x-input-error :messages="$errors->get('captcha')" class="mt-2" />
                @endif

                @php
                    $rememberMeProps = [
                        'initialChecked' => (bool) old('remember'),
                        'label' => 'Remember me',
                        'name' => 'remember',
                    ];
                @endphp

                <div class="flex items-center justify-between text-sm text-white/60">
                    <div
                        data-remember-me-checkbox-root
                        data-props='@json($rememberMeProps)'
                    >
                        <label class="flex items-center gap-2">
                            <input type="checkbox" name="remember" value="1" class="rounded bg-slate-800 border-white/20" @checked(old('remember')) />
                            Remember me
                        </label>
                    </div>

                    @if (Route::has('password.request'))
                        <a href="{{ route('password.request') }}" class="text-purple-400 hover:underline">Forgot password?</a>
                    @endif
                </div>

                <button type="submit" class="w-full rounded-lg py-3 font-medium bg-gradient-to-r from-purple-500 to-pink-500 hover:from-purple-400 hover:to-pink-400 text-white transition">Sign In</button>

                <p class="text-sm text-center text-white/60">Don’t have an account? <a href="{{ route('register') }}" class="text-purple-400 hover:underline">Create one</a></p>
            </form>
        </div>
    </div>
</div>
@if(($requiresCaptcha ?? false) && (($captcha['siteKey'] ?? '') !== '') && (($captcha['scriptUrl'] ?? '') !== ''))
    <script src="{{ $captcha['scriptUrl'] }}" async defer></script>
@endif
@include('partials.bot-fingerprint-script')
@endsection
