@extends('theme::layouts.auth')

@section('title', 'Prisijungti')

@section('content')
<h1>Prisijunkite</h1>
<p class="subtitle">Naudokite el. paštą ir slaptažodį</p>

{{-- Email just verified → show a one-time success banner. --}}
@if (session('email_verified') || request()->query('verified'))
    <div class="auth-alert success">
        <i class="bi bi-check-circle-fill me-1"></i>
        El. paštas patvirtintas. Prisijunkite, kad toliau naudotumėtės paskyra.
    </div>
@endif

{{-- Status flash (e.g., after successful password reset the Password broker sets 'status') --}}
@if (session('status'))
    <div class="auth-alert success">
        <i class="bi bi-check-circle-fill me-1"></i> {{ session('status') }}
    </div>
@endif

{{-- Error banner shown only for non-field-specific errors; field errors show inline below --}}
@if ($errors->has('email') && !$errors->has('password'))
    {{-- 'email' holds the "wrong credentials" message — show as banner, since the user
         can't tell which field is wrong anyway, and we don't want to leak it. --}}
    <div class="auth-alert error">
        <i class="bi bi-exclamation-circle-fill me-1"></i> {{ $errors->first('email') }}
    </div>
@endif

<form method="POST" action="{{ route(cms_route_name_for_current_locale(cms_current_environment() . '.auth.login.store')) }}" id="loginForm" novalidate>
    @csrf

    <div class="mb-3">
        <label for="email" class="form-label">El. paštas</label>
        <input type="email" id="email" name="email"
               value="{{ old('email', request()->query('email')) }}"
               class="form-control @error('email') is-invalid @enderror"
               required autocomplete="email"
               {{ request()->query('email') ? '' : 'autofocus' }}>
    </div>

    <div class="mb-2">
        <label for="password" class="form-label">Slaptažodis</label>
        <input type="password" id="password" name="password"
               class="form-control @error('password') is-invalid @enderror"
               required autocomplete="current-password"
               {{ request()->query('email') ? 'autofocus' : '' }}>
    </div>

    <div class="forgot-row">
        <div class="form-check mb-0">
            <input type="checkbox" name="remember" id="remember" class="form-check-input" {{ old('remember') ? 'checked' : '' }}>
            <label class="form-check-label" for="remember">Prisiminti mane</label>
        </div>
        <a href="{{ route(cms_route_name_for_current_locale(cms_current_environment() . '.auth.password.request')) }}">
            Pamiršote slaptažodį?
        </a>
    </div>

    <button type="submit" class="btn-brand">Prisijungti</button>
</form>

<div class="divider"></div>

<div class="meta-link">
    Neturite paskyros?
    <a href="{{ route(cms_route_name_for_current_locale(cms_current_environment() . '.auth.register')) }}">
        Registruotis
    </a>
</div>
@endsection
