/**
 * Settings Page Scripts
 * Handles collapsible panels, toggles, and variable clipboard
 */
jQuery(document).ready(function($) {
    'use strict';
    
    // Toggle email settings panel based on master toggle
    $('#email_enabled').on('change', function() {
        if ($(this).is(':checked')) {
            $('#email-settings-panel').addClass('is-open');
        } else {
            $('#email-settings-panel').removeClass('is-open');
        }
    });
    
    // Collapsible triggers
    $('.psf-collapsible-trigger').on('click', function() {
        var target = $(this).data('target');
        $(this).toggleClass('is-open');
        $('#' + target).toggleClass('is-open');
    });
    
    // Copy variable to clipboard on click
    $('.psf-variables-list code').on('click', function() {
        var text = $(this).text();
        var $el = $(this);
        
        if (navigator.clipboard) {
            navigator.clipboard.writeText(text).then(function() {
                // Brief visual feedback
                $el.css('background', '#c8e6c9');
                setTimeout(function() {
                    $el.css('background', '');
                }, 200);
            });
        }
    });
});
