<!-- Path: app/Views/auth/login.view.php -->
<div class="bg-slate-50 min-h-[calc(100vh-64px)] flex items-center justify-center py-12 px-4 sm:px-6 lg:px-8">
    <div class="max-w-md w-full bg-white rounded-xl shadow-lg border border-slate-200 overflow-hidden">
        
        <div class="bg-navy-950 p-6 text-center">
            <div class="w-16 h-16 bg-brandBlue-500 text-white rounded-full flex items-center justify-center text-3xl mx-auto shadow-md mb-4">
                <i class="fas fa-shield-alt"></i>
            </div>
            <h2 class="text-2xl font-bold text-white">Welcome Back</h2>
            <p class="text-slate-300 text-sm mt-1">Sign in to your ERCS account</p>
        </div>

        <div class="p-8">
            <form id="loginForm" class="space-y-6">
                <div>
                    <label for="email" class="block text-sm font-medium text-slate-700 mb-1">Email Address</label>
                    <div class="relative">
                        <div class="absolute inset-y-0 left-0 pl-3 flex items-center pointer-events-none">
                            <i class="fas fa-envelope text-slate-400"></i>
                        </div>
                        <input type="email" name="email" id="email" required class="block w-full pl-10 pr-3 py-3 border border-slate-300 rounded-md shadow-sm focus:outline-none focus:ring-2 focus:ring-brandBlue-500 focus:border-brandBlue-500 transition-colors" placeholder="you@example.com">
                    </div>
                </div>

                <div>
                    <div class="flex items-center justify-between mb-1">
                        <label for="password" class="block text-sm font-medium text-slate-700">Password</label>
                        <a href="{{APP_URL}}/forgot-password" class="text-sm font-medium text-brandBlue-600 hover:text-brandBlue-500">Forgot password?</a>
                    </div>
                    <div class="relative">
                        <div class="absolute inset-y-0 left-0 pl-3 flex items-center pointer-events-none">
                            <i class="fas fa-lock text-slate-400"></i>
                        </div>
                        <input type="password" name="password" id="password" required class="block w-full pl-10 pr-3 py-3 border border-slate-300 rounded-md shadow-sm focus:outline-none focus:ring-2 focus:ring-brandBlue-500 focus:border-brandBlue-500 transition-colors" placeholder="••••••••">
                    </div>
                </div>

                <button type="submit" id="submitBtn" class="w-full flex justify-center py-3 px-4 border border-transparent rounded-md shadow-sm text-sm font-bold text-white bg-navy-900 hover:bg-navy-800 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-navy-900 transition-colors">
                    Sign In <i class="fas fa-sign-in-alt ml-2 mt-1"></i>
                </button>
            </form>

            <div class="mt-6 text-center text-sm text-slate-600">
                Don't have an account? 
                <a href="{{APP_URL}}/register" class="font-medium text-brandBlue-600 hover:text-brandBlue-500">Create one now</a>
            </div>
        </div>
    </div>
</div>

@addScript
<script>
$(document).ready(function() {
    $('#loginForm').on('submit', function(e) {
        e.preventDefault();
        
        let $btn = $('#submitBtn');
        let originalText = $btn.html();
        
        $btn.html('<i class="fas fa-spinner fa-spin"></i> Authenticating...').prop('disabled', true);
        
        $.ajax({
            url: '{{APP_URL}}/login',
            type: 'POST',
            data: $(this).serialize(),
            success: function(response) {
                if(response.status === 'success') {
                    showNotification('success', 'Success', response.message);
                    setTimeout(function() {
                        window.location.href = '{{APP_URL}}' + response.redirect;
                    }, 1000);
                }
            },
            error: function(xhr) {
                let msg = 'Invalid credentials.';
                if(xhr.responseJSON && xhr.responseJSON.message) {
                    msg = xhr.responseJSON.message;
                } else if (xhr.responseJSON && xhr.responseJSON.errors) {
                    msg = Object.values(xhr.responseJSON.errors)[0][0]; 
                }
                showNotification('error', 'Login Failed', msg);
                $btn.html(originalText).prop('disabled', false);
            }
        });
    });
});
</script>
@endAddScript