jQuery(document).ready(function($) {
    $('#generate_article_btn').on('click', function() {
        var title = $('#custom_post_title').val();
        var word_count = $('#custom_word_count').val();
        
        // AJAX request
        $.ajax({
            url: customMetaBox.ajax_url,
            type: 'POST',
            data: {
                action: 'generate_article',
                title: title,
                word_count: word_count,
                nonce: customMetaBox.nonce
            },
            success: function(response) {
                if (response.success) {
                    // Set the generated article content in the hidden input field
                    $('#generated_article_content').val(response.data.content);
                    alert('Article generated successfully!');
                } else {
                    alert('Failed to generate article');
                }
            }
        });
    });
});
