<?php
include 'includes/db.php';

// Check if admin already exists
$check = $conn->query("SELECT id FROM admin_users WHERE username = 'admin'");
if ($check && $check->num_rows > 0) {
    echo "<p style='color:orange;'>Admin user already exists.</p>";
} else {
    $hashed = password_hash('admin123', PASSWORD_DEFAULT);
    $stmt = $conn->prepare("INSERT INTO admin_users (username, password) VALUES (?, ?)");
    $stmt->bind_param("ss", $username, $hashed);
    $username = 'admin';
    if ($stmt->execute()) {
        echo "<p style='color:green;'>✅ Admin user created successfully! Username: <b>admin</b>, Password: <b>admin123</b></p>";
    } else {
        echo "<p style='color:red;'>❌ Error creating admin: " . $conn->error . "</p>";
    }
    $stmt->close();
}

echo "<p><a href='admin/login.php'>Go to Login →</a></p>";
$conn->close();
?>
