<?php
/**
 * Simple test file to verify Zoho AJAX is working
 * Access this at: /wp-content/plugins/hvac-community-events/test-zoho-ajax.php
 */

// Load WordPress
require_once('../../../../../wp-load.php');

if (!is_admin() && !current_user_can('manage_options')) {
    wp_die('This test requires admin access. Please log in as an admin first.');
}

?>
<!DOCTYPE html>
<html>
<head>
    <title>Zoho AJAX Test</title>
    <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
</head>
<body>
    <h1>Zoho AJAX Connection Test</h1>
    
    <button id="test-simple">Test Simple AJAX</button>
    <button id="test-connection">Test Zoho Connection</button>
    
    <div id="results" style="margin-top: 20px; padding: 20px; border: 1px solid #ccc; background: #f9f9f9;">
        <h3>Results will appear here...</h3>
    </div>

    <script>
    jQuery(document).ready(function($) {
        // Test simple AJAX
        $('#test-simple').on('click', function() {
            $('#results').html('<p>Testing simple AJAX...</p>');
            
            $.ajax({
                url: '<?php echo admin_url('admin-ajax.php'); ?>',
                method: 'POST',
                data: {
                    action: 'hvac_zoho_simple_test'
                },
                success: function(response) {
                    $('#results').html('<div style="color: green;"><h3>Simple AJAX Success!</h3><pre>' + JSON.stringify(response, null, 2) + '</pre></div>');
                },
                error: function(xhr, status, error) {
                    $('#results').html('<div style="color: red;"><h3>Simple AJAX Error</h3><p>Status: ' + status + '</p><p>Error: ' + error + '</p><p>Response: ' + xhr.responseText + '</p></div>');
                }
            });
        });
        
        // Test connection
        $('#test-connection').on('click', function() {
            $('#results').html('<p>Testing Zoho connection...</p>');
            
            $.ajax({
                url: '<?php echo admin_url('admin-ajax.php'); ?>',
                method: 'POST',
                data: {
                    action: 'hvac_zoho_test_connection',
                    nonce: '<?php echo wp_create_nonce('hvac_zoho_nonce'); ?>'
                },
                success: function(response) {
                    var html = '<div style="color: green;"><h3>Connection Test Response</h3>';
                    html += '<h4>Success: ' + response.success + '</h4>';
                    html += '<pre>' + JSON.stringify(response, null, 2) + '</pre>';
                    html += '</div>';
                    $('#results').html(html);
                },
                error: function(xhr, status, error) {
                    $('#results').html('<div style="color: red;"><h3>Connection Test Error</h3><p>Status: ' + status + '</p><p>Error: ' + error + '</p><p>Response: ' + xhr.responseText + '</p></div>');
                }
            });
        });
    });
    </script>
</body>
</html>