/**
 * GistMag ATG Admin Settings JavaScript
 * Handles API key verification on the settings page
 */
(function($) {
    'use strict';

    $(document).ready(function() {
        $('#verify-api-key').on('click', function() {
            var button = $(this);
            var apiKey = $('#gistmag_atg_api_key').val();
            
            button.prop('disabled', true).text('Verifying...');
            
            $.ajax({
                url: ajaxurl,
                type: 'POST',
                data: {
                    action: 'gistmag_atg_verify_key',
                    api_key: apiKey,
                    nonce: gistmag_atg_settings.nonce
                },
                success: function(response) {
                    if (response.success) {
                        alert('API key is valid!');
                    } else {
                        alert('API key verification failed: ' + (response.data.message || 'Unknown error'));
                    }
                },
                error: function() {
                    alert('Error verifying API key');
                },
                complete: function() {
                    button.prop('disabled', false).text('Verify API Key');
                }
            });
        });
    });
})(jQuery);

