<?php
session_start();
include "includes/layout.php";
include __DIR__ . '/../database/search_log_config.php';

$id = $_SESSION['admin_id'];

if($_SERVER["REQUEST_METHOD"] === "POST"){
    $name = $_POST['admin_name'];
    $email = $_POST['admin_email'];

    $stmt = $log_conn->prepare("
        UPDATE admin_users SET admin_name=?, admin_email=? WHERE id=?
    ");
    $stmt->bind_param("ssi", $name, $email, $id);
    $stmt->execute();
    $stmt->close();

    $_SESSION['admin_name'] = $name;
    $success = "Profile updated successfully!";
}

$admin = $log_conn->query("
    SELECT * FROM admin_users WHERE id=$id
")->fetch_assoc();
?>

<h1>Edit Profile</h1>

<div class="card">
<?php if(isset($success)) echo "<p style='color:green;'>$success</p>"; ?>

<form method="POST">
<input type="text" name="admin_name"
value="<?= htmlspecialchars($admin['admin_name']) ?>"
style="width:100%;padding:10px;margin-bottom:10px;">

<input type="email" name="admin_email"
value="<?= htmlspecialchars($admin['admin_email']) ?>"
style="width:100%;padding:10px;margin-bottom:10px;">

<button class="btn">Update Profile</button>
</form>
</div>

<?php
$log_conn->close();
include "includes/footer.php";
?>