<?php
require_once "includes/config.php";

echo "<h2>Debug Admin Login</h2>";

// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}

// Get admin user
$sql = "SELECT id, username, password FROM admins WHERE username = 'admin' LIMIT 1";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
    $admin = $result->fetch_assoc();
    echo "<h3>Admin User Found:</h3>";
    echo "<pre>";
    print_r($admin);
    echo "</pre>";
    
    // Verify password
    $password = 'admin123';
    $isValid = password_verify($password, $admin['password']);
    
    echo "<h3>Password Verification:</h3>";
    echo "Password to verify: 'admin123'<br>";
    echo "Stored hash: " . $admin['password'] . "<br>";
    echo "Verification result: " . ($isValid ? '✅ Password is valid!' : '❌ Invalid password!');
    
    // If password is invalid, show how to reset it
    if (!$isValid) {
        echo "<h3>To reset password, run this SQL in your database:</h3>";
        $newHash = password_hash('admin123', PASSWORD_DEFAULT);
        echo "<pre>UPDATE admins SET password = '" . $newHash . "' WHERE username = 'admin';</pre>";
    }
} else {
    echo "No admin user found. Run this SQL to create one:<br>";
    $password = password_hash('admin123', PASSWORD_DEFAULT);
    echo "<pre>INSERT INTO admins (username, password, email) VALUES ('admin', '" . $password . "', 'admin@example.com');</pre>";
}

$conn->close();
?>
