@extends('layouts.auth')

@section('title', 'Masuk ke Sistem')

@section('content')
{{-- Status Live Badge --}}
<div class="brand-badge-box">
    <span class="pulse-indicator"></span>
    <span>Sistem Presensi Online</span>
</div>

{{-- Main Title --}}
<h2 class="brand-title-kinetic">Masuk ke Portal</h2>

{{-- Kinetic Rotating Subtitle (Moving Text) --}}
<div class="kinetic-subtitle-wrap">
    <span>Akses ke</span>
    <span class="kinetic-dynamic-text" id="kinetic-text">Presensi Geofencing GPS</span>
</div>

@if ($errors->any())
    <div class="alert alert-danger p-3 mb-3 rounded-3 border-0" style="background: rgba(239, 68, 68, 0.15); border: 1px solid rgba(239, 68, 68, 0.3); color: #fca5a5; font-size: 0.82rem;" role="alert">
        <div class="d-flex align-items-center gap-2 mb-1 fw-bold text-uppercase" style="font-size: 0.72rem;">
            <i class="bi bi-exclamation-octagon-fill"></i>
            <span>Kredensial Tidak Sesuai</span>
        </div>
        <ul class="mb-0 ps-3">
            @foreach ($errors->all() as $error)
                <li>{{ $error }}</li>
            @endforeach
        </ul>
    </div>
@endif

<form action="{{ route('login.post') }}" method="POST" id="loginForm">
    @csrf

    {{-- Email Input --}}
    <div class="form-group-sleek">
        <label class="sleek-label" for="login-email">Alamat Email</label>
        <div class="input-box-relative">
            <i class="bi bi-envelope lead-icon"></i>
            <input type="email" name="email" id="login-email" 
                class="sleek-input @error('email') is-invalid @enderror" 
                placeholder="nama@perusahaan.com" value="{{ old('email') }}" 
                required autofocus autocomplete="email">
        </div>
    </div>

    {{-- Password Input --}}
    <div class="form-group-sleek">
        <label class="sleek-label" for="login-password">Kata Sandi</label>
        <div class="input-box-relative">
            <i class="bi bi-lock lead-icon"></i>
            <input type="password" name="password" id="login-password" 
                class="sleek-input @error('password') is-invalid @enderror" 
                placeholder="Masukkan kata sandi" 
                required autocomplete="current-password">
            <button type="button" class="toggle-pwd-btn" onclick="togglePassword()" tabindex="-1" aria-label="Lihat sandi">
                <i class="bi bi-eye" id="eye-icon"></i>
            </button>
        </div>
    </div>

    {{-- Remember Checkbox --}}
    <div class="d-flex justify-content-between align-items-center mb-4">
        <div class="form-check mb-0">
            <input class="form-check-input" type="checkbox" name="remember" id="remember" {{ old('remember') ? 'checked' : '' }}>
            <label class="form-check-label" for="remember" style="font-size: 0.8rem; color: #94a3b8;">
                Ingat sesi perangkat ini
            </label>
        </div>
    </div>

    {{-- Action Button --}}
    <button type="submit" class="btn-action-primary">
        <span>Masuk ke Dashboard</span>
        <i class="bi bi-arrow-right"></i>
    </button>
</form>

{{-- Quick Demo Credentials Selector --}}
<div class="demo-bar-sleek">
    <div class="demo-bar-title">
        <span>Akses Pengujian Cepat</span>
        <span class="text-xs text-muted">1-Klik</span>
    </div>
    <div class="demo-chips-grid">
        <button type="button" class="demo-chip-btn" onclick="applyDemo('superadmin@absensi.test')">
            Super Admin
        </button>
        <button type="button" class="demo-chip-btn" onclick="applyDemo('admin@absensi.test')">
            HR Admin
        </button>
        <button type="button" class="demo-chip-btn" onclick="applyDemo('employee@absensi.test')">
            Karyawan
        </button>
    </div>
</div>

<script>
    // Kinetic Word Rotator
    const rotatingList = [
        "Presensi Geofencing GPS",
        "Validasi Koordinat Satelit",
        "Sinkronisasi Data Real-Time",
        "Monitoring Jadwal & Shift",
        "Manajemen Presensi Pintar"
    ];
    let rotIndex = 0;
    const rotElement = document.getElementById('kinetic-text');

    setInterval(() => {
        rotIndex = (rotIndex + 1) % rotatingList.length;
        if (rotElement) {
            rotElement.style.opacity = '0';
            rotElement.style.transform = 'translateY(4px)';
            setTimeout(() => {
                rotElement.innerText = rotatingList[rotIndex];
                rotElement.style.opacity = '1';
                rotElement.style.transform = 'translateY(0)';
            }, 200);
        }
    }, 2600);

    // Apply Demo User
    function applyDemo(email) {
        const emailField = document.getElementById('login-email');
        const passField = document.getElementById('login-password');
        if (emailField && passField) {
            emailField.value = email;
            passField.value = 'password';
            emailField.focus();
        }
    }
</script>
@endsection
