<?php
/**
 * TEMPORARY - Admin Password Reset
 * Visit this URL once, then DELETE the file immediately.
 * URL: http://localhost/hotel-booking/admin/reset.php
 */
require "../config/config.php";

// Create admins table if it doesn't exist
$conn->exec("CREATE TABLE IF NOT EXISTS admins (
    id INT AUTO_INCREMENT PRIMARY KEY,
    username VARCHAR(100) NOT NULL,
    email VARCHAR(150) NOT NULL UNIQUE,
    mypassword VARCHAR(255) NOT NULL,
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
)");

// Credentials - change these if you want
$username = 'Admin';
$email    = 'admin@hotel.com';
$password = 'admin123';
$hash     = password_hash($password, PASSWORD_DEFAULT);

// Insert or update admin
$check = $conn->prepare("SELECT id FROM admins WHERE email = :email");
$check->execute([':email' => $email]);

if($check->rowCount() > 0){
    $upd = $conn->prepare("UPDATE admins SET mypassword = :pw, username = :un WHERE email = :em");
    $upd->execute([':pw' => $hash, ':un' => $username, ':em' => $email]);
    $action = 'RESET';
} else {
    $ins = $conn->prepare("INSERT INTO admins (username, email, mypassword) VALUES (:u, :e, :p)");
    $ins->execute([':u' => $username, ':e' => $email, ':p' => $hash]);
    $action = 'CREATED';
}
?>
<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <title>Admin Reset</title>
  <style>
    body { background:#0a1628; display:flex; align-items:center; justify-content:center; min-height:100vh; margin:0; font-family:sans-serif; }
    .box { background:rgba(255,255,255,0.05); border:1px solid rgba(255,255,255,0.1); border-radius:16px; padding:40px; color:#fff; text-align:center; max-width:420px; }
    h2 { color:#4e9af1; }
    .cred { background:rgba(255,255,255,0.07); border-radius:8px; padding:16px; margin:16px 0; font-size:15px; text-align:left; }
    .cred strong { color:#4e9af1; }
    .btn { display:inline-block; margin-top:20px; padding:12px 32px; background:linear-gradient(135deg,#4e9af1,#1565c0); color:#fff; text-decoration:none; border-radius:8px; font-weight:700; }
    .warn { color:#ffd54f; font-size:13px; margin-top:16px; background:rgba(255,193,7,0.1); border:1px solid rgba(255,193,7,0.3); border-radius:8px; padding:10px; }
  </style>
</head>
<body>
  <div class="box">
    <h2>✅ Admin <?php echo $action; ?></h2>
    <p>Use these credentials to log in:</p>
    <div class="cred">
      <strong>Email:</strong> <?php echo $email; ?><br><br>
      <strong>Password:</strong> <?php echo $password; ?>
    </div>
    <a href="login.php" class="btn">→ Go to Login</a>
    <div class="warn">
      ⚠️ Delete this file after logging in!<br>
      <code style="font-size:11px;">admin/reset.php</code>
    </div>
  </div>
</body>
</html>
