<?php
include("../../includes/auth_check.php");
include("../../config/config.php");

if (isset($_POST['respond'])) {
    $feedback_id = intval($_POST['feedback_id']);
    $remarks = trim($_POST['remarks']);
    $status = $_POST['status']; // <-- Get selected status from dropdown (accepted/rejected)
    $admin_id = $_SESSION['user_id'];

    if (empty($remarks)) {
        echo "<script>alert('Please enter your remarks');history.back();</script>";
        exit;
    }

    // Update feedback with selected status (accepted/rejected)
    $stmt = $con->prepare("UPDATE feedbacks SET status = ?, remarks = ?, updated_at = NOW() WHERE feedback_id = ?");
    $stmt->bind_param("ssi", $status, $remarks, $feedback_id);

    if ($stmt->execute()) {
        echo "<script>alert('Response submitted successfully!');window.location.href='../admin/manage_feedback.php';</script>";
    } else {
        echo "<script>alert('Error while saving response: " . htmlspecialchars($stmt->error) . "');history.back();</script>";
    }
}
?>
