@extends('layouts.auth-master')

@section('content')
<div class="d-flex justify-content-center align-items-center" style="min-height: 100vh;">
    <div class="shadow-lg rounded p-4" style="background-color: white; width: 100%; max-width: 400px;">
        @if (session('success'))
        <div class="alert alert-success">
            {{ session('success') }}
        </div>
        @endif
        <form method="post" action="{{ route('login.perform') }}">
            @csrf

            <div class="text-center mb-3">
                <img src="{{ asset('assets/logo/logo.png') }}" alt="Logo" height="57">
                <div class="brand-text font-weight-light mt-1" style="color:#c93525;font-style: italic;font-size: 23px;font-weight:bold">Laporan Stok Malam</div>
            </div>

            <h1 class="h5 mb-4 text-center"><small>Web Portal</small></h1>

            @if ($errors->any())
            <div class="alert alert-danger">
                @foreach ($errors->all() as $error)
                    {{ $error }}
                @endforeach
            </div>
            @endif

            <div class="form-group form-floating mb-3">
                <input type="text" class="form-control @error('username') is-invalid @enderror" name="username" value="{{ old('username', Session::get('username')) }}" placeholder="Username" required autofocus>
                <label for="floatingName">Email atau Username</label>
                @error('username')
                <div class="invalid-feedback">{{ $message }}</div>
                @enderror
            </div>
            <div class="form-group form-floating mb-3 position-relative">
                <input type="password" class="form-control @error('password') is-invalid @enderror" name="password" id="password" value="{{ Session::get('password') }}" placeholder="Password" required>
                <label for="floatingPassword">Password</label>

                <!-- Icon mata kanan -->
                <span onclick="togglePassword()" class="position-absolute top-50 end-0 translate-middle-y me-3" style="cursor: pointer; z-index: 10;">
                    <i class="fas fa-eye" id="toggleIcon"></i>
                </span>

                @error('password')
                <div class="invalid-feedback">{{ $message }}</div>
                @enderror
            </div>
            <div class="d-flex justify-content-between mb-3">
                <!-- <a href="#" class="text-decoration-none small">Register</a> -->
                <!-- <a href="#" class="text-decoration-none me-3 small">Forgot Password?</a> -->
            </div>

            <button class="w-100 btn btn-warning mb-3" type="submit">Masuk</button>

            <div class="text-center mb-5"></div>



            <p class="text-muted text-sm text-center small mb-0">@include('auth.partials.copy')</p>
        </form>
    </div>
</div>

<script>
    let isSubmitting = false;
    document.querySelector('form').addEventListener('submit', function(e) {
        if (isSubmitting) {
            e.preventDefault();
            return false;
        }
        isSubmitting = true;
        const loader = document.getElementById('loaderkdnknz');
        if (loader) loader.style.display = 'block';
    });

    function togglePassword() {
        const input = document.getElementById('password');
        const icon = document.getElementById('toggleIcon');

        if (input.type === 'password') {
            input.type = 'text';
            icon.classList.remove('fa-eye');
            icon.classList.add('fa-eye-slash');
        } else {
            input.type = 'password';
            icon.classList.remove('fa-eye-slash');
            icon.classList.add('fa-eye');
        }
    }
</script>
@endsection