<?php
include 'db.php';
$message = '';
if ($_POST) {
    $u = $_POST['username'];
    $np = $_POST['new_password'];
    $stmt = $pdo->prepare('UPDATE users SET password=? WHERE username=?');
    if ($stmt->execute([$np, $u])) {
        $message = "Password reset successful! <a href='login.php'>Login</a>";
    } else {
        $message = "<span style='color:red;'>Error resetting password.</span>";
    }
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Reset Password - Review Stream</title>
<link rel="stylesheet" href="style.css">
<style>
.container { max-width:400px; margin:2rem auto; }
form { display:flex; flex-direction:column; gap:0.8rem; }
input[type="text"], input[type="password"] { padding:0.6rem; border-radius:6px; border:1px solid #ccc; }
button { padding:0.6rem; background:#dc3545; color:#fff; border:none; border-radius:6px; cursor:pointer; }
button:hover { background:#a71d2a; }
</style>
</head>
<body>
<div class="topbar">
  <div class="logo"><i class="fas fa-comments"></i> REVIEW STREAM</div>
  <div class="menu">
    <a href="index.php">Home</a>
    <a href="companies.php">Companies</a>
    <a href="login.php">Login</a>
  </div>
</div>
<div class="container">
  <div class="card">
    <h2 style="text-align:center;">Reset Password</h2>
    <?php if ($message): ?>
      <div style="text-align:center;"><?= $message ?></div>
    <?php endif; ?>
    <form method="post">
      <input name="username" type="text" placeholder="Enter your username" required>
      <input name="new_password" type="password" placeholder="New password" required>
      <button type="submit">Reset Password</button>
    </form>
  </div>
</div>
<footer>
  <div class="footer-menu">
    <a href="#">Privacy Policy</a> <a href="#">Terms of Use</a> <a href="#">About</a>
  </div>
  <p>Copyright 2025 Review Stream. All rights reserved.</p>
</footer>
</body>
</html>
