(function($) {
    'use strict';
    $(document).ready(function() {
        // Make sure walletUpData is globally available
        window.walletUpData = window.walletUpData || {};
        
        // Add a convenience function for AJAX requests
        window.walletUpAjax = function(action, data, callback) {
            // Create form data
            var formData = new FormData();
            formData.append('action', action);
            formData.append('nonce', window.walletUpData.nonce);
            
            // Add all data properties
            if (data) {
                for (var key in data) {
                    if (data.hasOwnProperty(key)) {
                        formData.append(key, data[key]);
                    }
                }
            }
            
            // Make the AJAX request
            $.ajax({
                url: window.walletUpData.ajaxUrl,
                method: 'POST',
                data: formData,
                processData: false,
                contentType: false,
                success: function(response) {
                    if (callback && typeof callback === 'function') {
                        callback(null, response);
                    }
                },
                error: function(xhr, status, error) {
                    if (callback && typeof callback === 'function') {
                        callback(error, null);
                    }
                }
            });
        };
        
        console.log('WalletUpPro AJAX initialized');
    });
})(jQuery);