<div class="wrap">
    <h1><?php _e('Subscription System Diagnostics', 'subscription-system'); ?></h1>
    
    <div class="card">
        <h2><?php _e('Database Connection Test', 'subscription-system'); ?></h2>
        <p><?php _e('Test the database connection and subscription table creation.', 'subscription-system'); ?></p>
        
        <button id="test-db-connection" class="button button-primary"><?php _e('Test Database Connection', 'subscription-system'); ?></button>
        <div id="db-connection-result" style="margin-top: 10px;"></div>
        
        <script>
        jQuery(document).ready(function($) {
            $('#test-db-connection').on('click', function() {
                var button = $(this);
                button.prop('disabled', true).text('<?php _e('Testing...', 'subscription-system'); ?>');
                
                $.ajax({
                    url: ajaxurl,
                    type: 'POST',
                    data: {
                        action: 'test_db_connection',
                        nonce: '<?php echo wp_create_nonce('subs_sys_admin_nonce'); ?>'
                    },
                    success: function(response) {
                        if (response.success) {
                            $('#db-connection-result').html('<div class="notice notice-success"><p>' + response.data.message + '</p></div>');
                        } else {
                            $('#db-connection-result').html('<div class="notice notice-error"><p>' + response.data.message + '</p></div>');
                        }
                        button.prop('disabled', false).text('<?php _e('Test Database Connection', 'subscription-system'); ?>');
                    },
                    error: function() {
                        $('#db-connection-result').html('<div class="notice notice-error"><p><?php _e('AJAX request failed', 'subscription-system'); ?></p></div>');
                        button.prop('disabled', false).text('<?php _e('Test Database Connection', 'subscription-system'); ?>');
                    }
                });
            });
        });
        </script>
    </div>
    
    <div class="card" style="margin-top: 20px;">
        <h2><?php _e('Test Subscription Creation', 'subscription-system'); ?></h2>
        <p><?php _e('Test creating a subscription record in the database.', 'subscription-system'); ?></p>
        
        <button id="test-subscription-creation" class="button button-primary"><?php _e('Create Test Subscription', 'subscription-system'); ?></button>
        <div id="subscription-creation-result" style="margin-top: 10px;"></div>
        
        <script>
        jQuery(document).ready(function($) {
            $('#test-subscription-creation').on('click', function() {
                var button = $(this);
                button.prop('disabled', true).text('<?php _e('Creating...', 'subscription-system'); ?>');
                
                $.ajax({
                    url: ajaxurl,
                    type: 'POST',
                    data: {
                        action: 'test_subscription_creation',
                        nonce: '<?php echo wp_create_nonce('subs_sys_admin_nonce'); ?>'
                    },
                    success: function(response) {
                        if (response.success) {
                            $('#subscription-creation-result').html('<div class="notice notice-success"><p>' + response.data.message + '</p></div>');
                        } else {
                            $('#subscription-creation-result').html('<div class="notice notice-error"><p>' + response.data.message + '</p></div>');
                        }
                        button.prop('disabled', false).text('<?php _e('Create Test Subscription', 'subscription-system'); ?>');
                    },
                    error: function() {
                        $('#subscription-creation-result').html('<div class="notice notice-error"><p><?php _e('AJAX request failed', 'subscription-system'); ?></p></div>');
                        button.prop('disabled', false).text('<?php _e('Create Test Subscription', 'subscription-system'); ?>');
                    }
                });
            });
        });
        </script>
    </div>
</div> 