<?php session_start();
include "config.php";
$id = $_GET['id'];
$stmt = $dbh->prepare("SELECT * FROM ea_tools WHERE id = ?");
$stmt->execute([$id]);
$ea = $stmt->fetch(PDO::FETCH_ASSOC);

if ($_SERVER["REQUEST_METHOD"] === "POST") {
    $stmt = $dbh->prepare("UPDATE ea_tools SET category=?, title=?, income_last_year=?, description=?, price=?, old_price=? WHERE id=?");
    $stmt->execute([
        $_POST['category'], $_POST['title'], $_POST['income'], $_POST['description'], $_POST['price'], $_POST['old_price'], $id
    ]);
    header("Location: view.php");
    exit;
}
?>
<!DOCTYPE html>
<html>
<head>
  <title>Edit EA Tool</title>
  <style>
    body { background: #111; color: #eee; font-family: Arial; padding: 20px; }
    form { max-width: 600px; margin: auto; background: #1a1a1a; padding: 20px; border-radius: 10px; }
    input, textarea, select { width: 100%; padding: 10px; margin: 10px 0; background: #333; color: #fff; border: none; border-radius: 5px; }
    input[type="submit"] { background: #0b5ed7; cursor: pointer; }
    input[type="submit"]:hover { background: #0a53be; }
  </style>
</head>
<body>
    <?php include "includes/header.php";?>
  <h2 style="text-align:center;">Edit EA Tool</h2>
 <form method="post">
  <label>Category</label>
  <select name="category">
    <?php
    $categories = ['Tools', 'Martin', 'Shock', 'Trend', 'Grid', 'Comprehensive'];
    foreach ($categories as $cat) {
        $selected = $ea['category'] === $cat ? 'selected' : '';
        echo "<option $selected>$cat</option>";
    }
    ?>
  </select>

  <label>Title</label>
  <input type="text" name="title" value="<?= htmlspecialchars($ea['title']) ?>" placeholder="Enter EA title">

  <label>Income Last Year</label>
  <input type="text" name="income" value="<?= htmlspecialchars($ea['income_last_year']) ?>" placeholder="e.g. +120.00%">

  <label>Description</label>
  <textarea name="description" rows="4" placeholder="Enter a short description"><?= htmlspecialchars($ea['description']) ?></textarea>

  <label>Price</label>
  <input type="text" name="price" value="<?= $ea['price'] ?>" placeholder="e.g. 0.99">

  <label>Old Price</label>
  <input type="text" name="old_price" value="<?= $ea['old_price'] ?>" placeholder="e.g. 980.00">

  <input type="submit" value="Update EA Tool">
</form>

  <?php include "includes/footer.php"; ?>
</body>
</html>
