<?php
require_once __DIR__ . '/../../../includes/auth.php';
requireLogin();

require_once __DIR__ . '/../../../config/database.php';

$company_id = $_SESSION['company_id'];

$watcher_id = isset($_POST['watcher_id']) ? (int)$_POST['watcher_id'] : 0;
$ticket_id  = isset($_POST['ticket_id']) ? (int)$_POST['ticket_id'] : 0;

if ($watcher_id > 0) {

    $stmt = $pdo->prepare("
        DELETE FROM ticket_watchers
        WHERE id = ? AND company_id = ?
    ");
    $stmt->execute([$watcher_id, $company_id]);
}

header("Location: view.php?id=" . $ticket_id);
exit;