<?php
session_start();
require_once __DIR__ . '/../../config/db.php';

if (!isset($_SESSION['user_id'])) {
    header("Location: ../../auth/login.php");
    exit;
}

$user_id = $_SESSION['user_id'];

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $ticket_id = $_POST['ticket_id'] ?? null;
    $body = trim($_POST['body'] ?? '');

    if ($ticket_id && $body) {
        $stmt = $pdo->prepare("INSERT INTO comments (ticket_id, user_id, body) VALUES (?, ?, ?)");
        $stmt->execute([$ticket_id, $user_id, $body]);
    }
    header("Location: ../issues/");
    exit;
}
?>
