// UI Logic for the API Toggle switch
window.toggleApiSettings = function(checkbox) {
    const apiSettingsBlock = document.getElementById('apiSettingsBlock');
    const manualSettingsBlock = document.getElementById('manualSettingsBlock');
    
    if(checkbox.checked) {
        apiSettingsBlock.style.display = 'block';
        manualSettingsBlock.style.display = 'none';
    } else {
        apiSettingsBlock.style.display = 'none';
        manualSettingsBlock.style.display = 'block';
    }
};

// UI Logic for Referral Toggle
window.toggleReferralSettings = function(checkbox) {
    const refSettingsBlock = document.getElementById('referralSettingsBlock');
    
    if(checkbox.checked) {
        refSettingsBlock.style.display = 'block';
        refSettingsBlock.style.animation = 'fadeIn 0.3s ease';
    } else {
        refSettingsBlock.style.display = 'none';
    }
};

// Save Function Visual Feedback
window.testFormSave = function(btnElement) {
    const originalHTML = btnElement.innerHTML;
    btnElement.innerHTML = '<i class="fa-solid fa-spinner fa-spin"></i> Saving...';
    
    // We do not prevent default here so form POST continues natively
    setTimeout(() => {
        btnElement.innerHTML = '<i class="fa-solid fa-check"></i> Configuration Saved';
        btnElement.style.backgroundColor = '#059669'; 
        
        setTimeout(() => {
            btnElement.innerHTML = originalHTML;
            btnElement.style.backgroundColor = ''; 
        }, 2000);
    }, 1000);
};