@extends('layouts.guest')
@section('title', 'Sign In')

@section('content')
    <h5 class="fw-semibold mb-3">Welcome back 👋</h5>

    @if($errors->any())
        <div class="alert alert-danger py-2 small">{{ $errors->first() }}</div>
    @endif

    <form method="POST" action="{{ route('login') }}">
        @csrf
        <div class="mb-3">
            <label class="form-label">Email</label>
            <div class="input-group">
                <span class="input-group-text"><i class="bi bi-envelope"></i></span>
                <input type="email" name="email" value="{{ old('email') }}" class="form-control @error('email') is-invalid @enderror" placeholder="you@school.test" required autofocus>
            </div>
        </div>
        <div class="mb-3">
            <label class="form-label">Password</label>
            <div class="input-group">
                <span class="input-group-text"><i class="bi bi-lock"></i></span>
                <input type="password" name="password" class="form-control" placeholder="••••••••" required>
            </div>
        </div>
        <div class="d-flex justify-content-between align-items-center mb-3">
            <div class="form-check">
                <input class="form-check-input" type="checkbox" name="remember" id="remember">
                <label class="form-check-label small" for="remember">Remember me</label>
            </div>
            <a href="{{ route('password.request') }}" class="small">Forgot password?</a>
        </div>
        <button class="btn btn-primary w-100 py-2">Sign In <i class="bi bi-box-arrow-in-right ms-1"></i></button>
    </form>

    <div class="mt-4 p-3 rounded bg-light small">
        <div class="fw-semibold mb-2 text-muted">Demo accounts <span class="text-muted">— click to fill (password: <code>password</code>)</span></div>
        @php
            $demos = [
                ['Super Admin', 'superadmin@school.test', 'shield-lock', 'primary'],
                ['School Admin', 'admin@school.test', 'person-badge', 'primary'],
                ['Accountant', 'accountant@school.test', 'cash-coin', 'warning'],
                ['Parent', 'parent@school.test', 'people', 'success'],
                ['Student', 'student@school.test', 'mortarboard', 'info'],
            ];
        @endphp
        <div class="d-flex flex-column gap-1">
            @foreach($demos as [$role, $email, $icon, $tone])
                <button type="button" class="btn btn-sm btn-light border bg-white d-flex align-items-center gap-2 text-start js-demo" data-email="{{ $email }}">
                    <span class="badge bg-soft-{{ $tone }}"><i class="bi bi-{{ $icon }} me-1"></i>{{ $role }}</span>
                    <span class="text-muted">{{ $email }}</span>
                    <span class="ms-auto text-muted">password</span>
                </button>
            @endforeach
        </div>
    </div>

    @push('scripts')
    <script>
        document.querySelectorAll('.js-demo').forEach(function (btn) {
            btn.addEventListener('click', function () {
                document.querySelector('input[name=email]').value = this.dataset.email;
                document.querySelector('input[name=password]').value = 'password';
            });
        });
    </script>
    @endpush
@endsection
