false, 'error' => 'Video ID required']); exit; } $data = $comments->getThreadedComments($video_id, $limit, $offset, $sort); echo json_encode(['success' => true, 'comments' => $data]); break; case 'replies': $comment_id = $_GET['comment_id'] ?? null; $limit = intval($_GET['limit'] ?? 10); if (!$comment_id) { http_response_code(400); echo json_encode(['success' => false, 'error' => 'Comment ID required']); exit; } $data = $comments->getReplies($comment_id, $limit); echo json_encode(['success' => true, 'replies' => $data]); break; case 'post': if (!$current_user_id) { http_response_code(401); echo json_encode(['success' => false, 'error' => 'Authentication required']); exit; } $input = json_decode(file_get_contents('php://input'), true) ?: $_POST; $video_id = $input['video_id'] ?? null; $comment_text = $input['comment'] ?? null; $parent_comment_id = $input['parent_comment_id'] ?? null; if (!$video_id || !$comment_text) { http_response_code(400); echo json_encode(['success' => false, 'error' => 'Video ID and comment text required']); exit; } $comment_id = $comments->postComment($video_id, $current_user_id, $comment_text, $parent_comment_id); echo json_encode(['success' => true, 'comment_id' => $comment_id]); break; case 'react': if (!$current_user_id) { http_response_code(401); echo json_encode(['success' => false, 'error' => 'Authentication required']); exit; } $input = json_decode(file_get_contents('php://input'), true) ?: $_POST; $comment_id = $input['comment_id'] ?? null; $reaction_type = $input['reaction_type'] ?? 'like'; if (!$comment_id) { http_response_code(400); echo json_encode(['success' => false, 'error' => 'Comment ID required']); exit; } $comments->addReaction($comment_id, $current_user_id, $reaction_type); echo json_encode(['success' => true]); break; case 'unreact': if (!$current_user_id) { http_response_code(401); echo json_encode(['success' => false, 'error' => 'Authentication required']); exit; } $input = json_decode(file_get_contents('php://input'), true) ?: $_POST; $comment_id = $input['comment_id'] ?? null; $reaction_type = $input['reaction_type'] ?? 'like'; if (!$comment_id) { http_response_code(400); echo json_encode(['success' => false, 'error' => 'Comment ID required']); exit; } $comments->removeReaction($comment_id, $current_user_id, $reaction_type); echo json_encode(['success' => true]); break; case 'edit': if (!$current_user_id) { http_response_code(401); echo json_encode(['success' => false, 'error' => 'Authentication required']); exit; } $input = json_decode(file_get_contents('php://input'), true) ?: $_POST; $comment_id = $input['comment_id'] ?? null; $new_text = $input['comment'] ?? null; if (!$comment_id || !$new_text) { http_response_code(400); echo json_encode(['success' => false, 'error' => 'Comment ID and new text required']); exit; } $success = $comments->editComment($comment_id, $current_user_id, $new_text); if ($success) { echo json_encode(['success' => true]); } else { http_response_code(403); echo json_encode(['success' => false, 'error' => 'Permission denied']); } break; case 'pin': if (!$current_user_id) { http_response_code(401); echo json_encode(['success' => false, 'error' => 'Authentication required']); exit; } $input = json_decode(file_get_contents('php://input'), true) ?: $_POST; $comment_id = $input['comment_id'] ?? null; if (!$comment_id) { http_response_code(400); echo json_encode(['success' => false, 'error' => 'Comment ID required']); exit; } $success = $comments->pinComment($comment_id, $current_user_id); if ($success) { echo json_encode(['success' => true]); } else { http_response_code(403); echo json_encode(['success' => false, 'error' => 'Permission denied']); } break; default: http_response_code(400); echo json_encode(['success' => false, 'error' => 'Invalid action']); }