<?php
$pageTitle = 'Admin Credentials';
ob_start();
?>

<div class="bg-dark rounded-lg shadow-lg p-6">
    <h2 class="text-2xl font-bold mb-6">Admin Credentials</h2>
    
    <?php if ($success): ?>
        <div class="bg-green-800 text-white p-4 rounded-md mb-6">
            <i class="fas fa-check-circle mr-2"></i> Credentials updated successfully!
        </div>
    <?php endif; ?>
    
    <?php if (!empty($error)): ?>
        <div class="bg-red-800 text-white p-4 rounded-md mb-6">
            <i class="fas fa-exclamation-circle mr-2"></i> <?= htmlspecialchars($error) ?>
        </div>
    <?php endif; ?>
    
    <div class="bg-sidebar-bg rounded-lg p-6">
        <p class="text-gray-400 mb-6">
            Update your admin email and password. These credentials will be automatically updated in the .env file.
            <br>
            <span class="text-yellow-500"><i class="fas fa-exclamation-triangle mr-1"></i> Note: You will need to log in again after changing your credentials.</span>
        </p>
        
        <form action="/admin/credentials" method="POST">
            <div class="mb-4">
                <label for="email" class="block text-sm font-medium text-gray-400 mb-1">Email Address</label>
                <input 
                    type="email" 
                    id="email" 
                    name="email" 
                    value="<?= htmlspecialchars($currentEmail) ?>"
                    required
                    class="bg-dark border border-gray-700 rounded px-4 py-2 w-full focus:outline-none focus:ring-2 focus:ring-primary"
                >
            </div>
            
            <div class="mb-4">
                <label for="password" class="block text-sm font-medium text-gray-400 mb-1">New Password</label>
                <input 
                    type="password" 
                    id="password" 
                    name="password" 
                    required
                    minlength="8"
                    class="bg-dark border border-gray-700 rounded px-4 py-2 w-full focus:outline-none focus:ring-2 focus:ring-primary"
                >
                <p class="text-xs text-gray-500 mt-1">Password must be at least 8 characters long.</p>
            </div>
            
            <div class="mb-6">
                <label for="confirm_password" class="block text-sm font-medium text-gray-400 mb-1">Confirm Password</label>
                <input 
                    type="password" 
                    id="confirm_password" 
                    name="confirm_password" 
                    required
                    minlength="8"
                    class="bg-dark border border-gray-700 rounded px-4 py-2 w-full focus:outline-none focus:ring-2 focus:ring-primary"
                >
            </div>
            
            <div class="flex justify-end">
                <button type="submit" class="bg-primary hover:bg-secondary text-white px-4 py-2 rounded">
                    <i class="fas fa-save mr-2"></i> Update Credentials
                </button>
            </div>
        </form>
    </div>
</div>

<script>
    // Password confirmation validation
    const password = document.getElementById('password');
    const confirmPassword = document.getElementById('confirm_password');
    
    function validatePassword() {
        if (password.value !== confirmPassword.value) {
            confirmPassword.setCustomValidity("Passwords don't match");
        } else {
            confirmPassword.setCustomValidity('');
        }
    }
    
    password.addEventListener('change', validatePassword);
    confirmPassword.addEventListener('keyup', validatePassword);
</script>

<?php
$content = ob_get_clean();
include __DIR__ . '/layout.php';
?> 