<?php
require_once 'includes/config.php';
require_once 'includes/db.php';
require_once 'includes/functions.php';

// Test the updateProductComment function
if (isLoggedIn()) {
    echo "<h1>Testing updateProductComment Function</h1>";
    
    // Try to update a comment
    $comment_id = 1; // Replace with an actual comment ID
    $user_id = $_SESSION['user_id'];
    $new_comment = "This is a test update comment.";
    
    echo "<p>Attempting to update comment ID: " . $comment_id . "</p>";
    echo "<p>User ID: " . $user_id . "</p>";
    echo "<p>New comment: " . $new_comment . "</p>";
    
    $result = updateProductComment($pdo, $comment_id, $user_id, $new_comment);
    
    if ($result) {
        echo "<p style='color: green;'>✓ Comment updated successfully</p>";
    } else {
        echo "<p style='color: red;'>✗ Failed to update comment</p>";
    }
    
    // Check if the comment was actually updated
    $stmt = $pdo->prepare("SELECT * FROM product_comments WHERE id = ?");
    $stmt->execute([$comment_id]);
    $comment = $stmt->fetch(PDO::FETCH_ASSOC);
    
    if ($comment) {
        echo "<p>Updated comment in database:</p>";
        echo "<pre>" . print_r($comment, true) . "</pre>";
    } else {
        echo "<p>Comment not found in database</p>";
    }
} else {
    echo "<p>Please login to test the update comment functionality.</p>";
    echo "<p><a href='auth/login.php'>Login</a></p>";
}

echo "<p><a href='products/view.php?id=2'>View Product</a></p>";
?>