/**
 * Settings Page JavaScript for Subscription System
 *
 * @package    Subscription_System
 * @subpackage Subscription_System/admin/js
 */

(function( $ ) {
    'use strict';

    /**
     * Initialize settings functionality
     */
    function initSettings() {
        // Toggle switch animation
        $('.toggle-input').on('change', function() {
            var toggleText = $(this).closest('.field-control').find('.toggle-text');
            var isChecked = $(this).is(':checked');
            
            toggleText.text(isChecked ? 'Enabled' : 'Disabled');
            
            // Add visual feedback
            var toggleLabel = $(this).next('.toggle-label');
            toggleLabel.addClass('animate');
            setTimeout(function() {
                toggleLabel.removeClass('animate');
            }, 300);
        });

        // Form submission with loading state
        $('form').on('submit', function() {
            var submitButton = $('.button-save');
            var originalText = submitButton.text();
            
            submitButton.text('Saving...').prop('disabled', true);
            
            // Re-enable after form submission (WordPress will handle the redirect)
            setTimeout(function() {
                submitButton.text(originalText).prop('disabled', false);
            }, 3000);
        });

        // Check for AJAX success messages
        success: function(response) {
            // ... existing code ...
            // Look for: 'Settings saved.' or similar
            // ... existing code ...
        }
    }

    /**
     * Document ready
     */
    $(document).ready(function() {
        initSettings();
    });

})( jQuery ); 