<?php
require_once 'db.php';

// Generate correct hash for 'admin1234'
$password = 'admin1234';
$hash = password_hash($password, PASSWORD_DEFAULT);

// Update or insert admin
$check = $conn->query("SELECT id FROM admin_users WHERE username='admin'")->fetch_assoc();

if ($check) {
    $stmt = $conn->prepare("UPDATE admin_users SET password=? WHERE username='admin'");
    $stmt->bind_param("s", $hash);
    $stmt->execute();
    echo "<p style='color:green;font-size:18px;font-family:sans-serif'>✅ Admin password reset successfully!</p>";
} else {
    $name = 'Super Admin';
    $stmt = $conn->prepare("INSERT INTO admin_users (username, password, name) VALUES ('admin', ?, ?)");
    $stmt->bind_param("ss", $hash, $name);
    $stmt->execute();
    echo "<p style='color:green;font-size:18px;font-family:sans-serif'>✅ Admin account created successfully!</p>";
}

echo "<p style='font-family:sans-serif'>Username: <strong>admin</strong><br>Password: <strong>admin1234</strong></p>";
echo "<p style='font-family:sans-serif'><a href='admin_login.php'>Go to Admin Login →</a></p>";

// Delete this file after use reminder
echo "<p style='color:red;font-family:sans-serif;font-size:13px'>⚠️ Delete this file (reset_admin.php) from your server after use!</p>";
?>