<?php
/**
 * Simple TEC Community Events Test for Staging
 * 
 * Run this on staging server to test TEC shortcode functionality
 */

// WordPress bootstrap - adjust path for staging server
if (file_exists(__DIR__ . '/wp-load.php')) {
    require_once(__DIR__ . '/wp-load.php');
} elseif (file_exists(__DIR__ . '/../wp-load.php')) {
    require_once(__DIR__ . '/../wp-load.php');
} elseif (file_exists(__DIR__ . '/../../wp-load.php')) {
    require_once(__DIR__ . '/../../wp-load.php');
} elseif (file_exists(__DIR__ . '/../../../wp-load.php')) {
    require_once(__DIR__ . '/../../../wp-load.php');
} else {
    die('Cannot find wp-load.php');
}

header('Content-Type: text/html; charset=utf-8');

echo "<!DOCTYPE html><html><head><title>TEC Test</title>";
echo "<style>body { font-family: Arial, sans-serif; margin: 20px; } .pass { color: green; } .fail { color: red; } .warning { color: orange; }</style>";
echo "</head><body>";

echo "<h1>TEC Community Events Test - Staging</h1>";

// Test 1: Plugin Status
echo "<h2>1. Plugin Status</h2>";
$tec_active = is_plugin_active('the-events-calendar/the-events-calendar.php');
$tec_ce_active = is_plugin_active('the-events-calendar-community-events/tribe-community-events.php');

echo "<p>TEC Main: " . ($tec_active ? '<span class="pass">✓ Active</span>' : '<span class="fail">✗ Inactive</span>') . "</p>";
echo "<p>TEC Community: " . ($tec_ce_active ? '<span class="pass">✓ Active</span>' : '<span class="fail">✗ Inactive</span>') . "</p>";

// Test 2: Shortcode Registration
echo "<h2>2. Shortcode Status</h2>";
echo "<p>[tribe_community_events]: " . (shortcode_exists('tribe_community_events') ? '<span class="pass">✓ Registered</span>' : '<span class="fail">✗ Not Registered</span>') . "</p>";
echo "<p>[hvac_create_event]: " . (shortcode_exists('hvac_create_event') ? '<span class="pass">✓ Registered</span>' : '<span class="fail">✗ Not Registered</span>') . "</p>";
echo "<p>[hvac_edit_event]: " . (shortcode_exists('hvac_edit_event') ? '<span class="pass">✓ Registered</span>' : '<span class="fail">✗ Not Registered</span>') . "</p>";

// Test 3: Function Availability
echo "<h2>3. Function Availability</h2>";
echo "<p>tribe_community_events_init(): " . (function_exists('tribe_community_events_init') ? '<span class="pass">✓ Available</span>' : '<span class="fail">✗ Not Available</span>') . "</p>";

// Test 4: Shortcode Callbacks
echo "<h2>4. Shortcode Callbacks</h2>";
global $shortcode_tags;

if (isset($shortcode_tags['hvac_edit_event'])) {
    $callback = $shortcode_tags['hvac_edit_event'];
    if (is_array($callback)) {
        echo "<p>hvac_edit_event callback: <code>" . get_class($callback[0]) . "::" . $callback[1] . "()</code></p>";
    } else {
        echo "<p>hvac_edit_event callback: <code>$callback</code></p>";
    }
} else {
    echo "<p>hvac_edit_event: <span class='fail'>No callback found</span></p>";
}

// Test 5: Direct Shortcode Test
echo "<h2>5. Direct TEC Shortcode Test</h2>";

if (shortcode_exists('tribe_community_events')) {
    echo "<h3>Testing [tribe_community_events view=\"submission_form\"]:</h3>";
    echo "<div style='border: 1px solid #ccc; padding: 10px; max-height: 300px; overflow: auto;'>";
    
    // Capture any PHP errors
    ob_start();
    $output = do_shortcode('[tribe_community_events view="submission_form"]');
    $errors = ob_get_clean();
    
    if ($errors) {
        echo "<div class='fail'><strong>PHP Errors:</strong><pre>" . esc_html($errors) . "</pre></div>";
    }
    
    if (trim($output)) {
        echo "<div class='pass'><strong>Output Length:</strong> " . strlen($output) . " characters</div>";
        echo "<div><strong>First 500 chars:</strong><br>" . esc_html(substr($output, 0, 500)) . "...</div>";
    } else {
        echo "<div class='fail'><strong>No output generated</strong></div>";
    }
    
    echo "</div>";
} else {
    echo "<p class='fail'>Cannot test - tribe_community_events shortcode not available</p>";
}

echo "</body></html>";
?>