/**
 * JavaScript for the SEO Debug page
 */
jQuery(document).ready(function($) {
    // Test with vanilla JavaScript
    document.getElementById('test-vanilla-button').addEventListener('click', function() {
        console.log('Vanilla JS button clicked');
        document.getElementById('vanilla-results').innerHTML = 'Sending AJAX request...';
        
        var xhr = new XMLHttpRequest();
        xhr.open('POST', easyAiSeoDebug.ajaxUrl, true);
        xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
        
        xhr.onreadystatechange = function() {
            if (xhr.readyState === 4) {
                console.log('Response status:', xhr.status);
                console.log('Response text:', xhr.responseText);
                
                if (xhr.status === 200) {
                    try {
                        var response = JSON.parse(xhr.responseText);
                        document.getElementById('vanilla-results').innerHTML = '<pre>' + JSON.stringify(response, null, 2) + '</pre>';
                    } catch (e) {
                        document.getElementById('vanilla-results').innerHTML = 'Error parsing response: ' + e.message + '<br>Raw response: ' + xhr.responseText;
                    }
                } else {
                    document.getElementById('vanilla-results').innerHTML = 'Error: ' + xhr.status + ' ' + xhr.statusText;
                }
            }
        };
        
        xhr.send('action=easyaibloggen_analyze_keyword_density&nonce=' + easyAiSeoDebug.nonce + '&postId=1&auto_get_keyword=true');
    });

    // Test with jQuery
    $('#test-ajax-button').on('click', function() {
        console.log('jQuery button clicked');
        $('#test-results').html('Sending AJAX request...');
        
        $.ajax({
            url: easyAiSeoDebug.ajaxUrl,
            type: 'POST',
            data: {
                action: 'easyaibloggen_analyze_keyword_density',
                nonce: easyAiSeoDebug.nonce,
                postId: 1,
                test: 'true',
                auto_get_keyword: true
            },
            success: function(response) {
                console.log('Response:', response);
                $('#test-results').html('<pre>' + JSON.stringify(response, null, 2) + '</pre>');
            },
            error: function(xhr, status, error) {
                console.error('Error:', error);
                $('#test-results').html('Error: ' + error + '<br>Status: ' + status + '<br>Response: ' + xhr.responseText);
            }
        });
    });
}); 