jQuery(document).ready(function($) {
    // Add body class for shortcodes page
    $('body').addClass('shortcodes-page-active');

    function updateShortcode() {
        var text = $('#shortcode_text').val();
        var showLabel = $('#shortcode_show_label').is(':checked');
        
        // Start with the basic shortcode structure
        var shortcode = '[mementor-tts';
        
        // Add label attribute only if it's turned off (since "yes" is default)
        if (!showLabel) {
            shortcode += ' label="no"';
        }
        
        // Add the text content
        shortcode += ']' + (text || 'Your text here') + '[/mementor-tts]';
        
        // Update the output
        $('.mementor-tts-generator-output code').text(shortcode);
    }

    // Bind event listeners
    $('#shortcode_text').on('input', updateShortcode);
    $('#shortcode_show_label').on('change', updateShortcode);

    // Initialize copy button functionality
    $('.mementor-tts-copy-button').on('click', function() {
        var code = $(this).siblings('code').text();
        var tempTextarea = $('<textarea>').val(code).appendTo('body').select();
        document.execCommand('copy');
        tempTextarea.remove();
        
        // Visual feedback
        var $button = $(this);
        var $icon = $button.find('.dashicons');
        $icon.removeClass('dashicons-clipboard').addClass('dashicons-yes');
        setTimeout(function() {
            $icon.removeClass('dashicons-yes').addClass('dashicons-clipboard');
        }, 1000);
    });

    // Add event listeners for PRO toggles (for visual feedback only)
    $('.mementor-tts-generator-option input[type="checkbox"][disabled]').on('click', function(e) {
        e.preventDefault(); // Prevent default behavior
        var $label = $(this).closest('.mementor-tts-toggle').find('label:first');
        var featureName = $label.text().trim().split('PRO')[0].trim();
        alert('The ' + featureName + ' feature is only available in the PRO version.');
    });

    // Initialize shortcode on page load
    updateShortcode();
}); 