(function ($) {
    'use strict';
    //---------------------------------------------------------------------------------
    //---------------------------------------------------------------------------------
    window.TerminKalender = window.TerminKalender || {};
    //---------------------------------------------------------------------------------
    //---------------------------------------------------------------------------------
    // Auto-open Welcome Screen for new users
    $(function () {
        if (typeof tkAdminSettings !== 'undefined' && tkAdminSettings.show_welcome_screen) {
            var attempts = 0;
            var tryOpen = setInterval(function () {
                if ($('#help-dialog').hasClass('ui-dialog-content')) {
                    $('#help-dialog').dialog('open');
                    clearInterval(tryOpen);
                }
                attempts++;
                if (attempts > 20) clearInterval(tryOpen);
            }, 500);
        }
    });
    //---------------------------------------------------------------------------------

    //---------------------------------------------------------------------------------
    // Help Info ein und ausblenden
    /*        $('[name="ter_kal_help_toggle"]').on('click', function () {
                $(this).next().toggle(500);
            });*/
    //------------------------------------------------------------------
    // Uncomment if needed
    /*
    $('#toggle-trigger').click(function() {
        var toggleDiv = $('#toggle-div');
        var iconSpan = $('#toggle-icon');
        toggleDiv.slideToggle(function() {
            // Toggle dashicon arrow based on the toggle state
            iconSpan.toggleClass('dashicons-arrow-down-alt2', toggleDiv.is(':hidden'));
            iconSpan.toggleClass('dashicons-arrow-up-alt2', !toggleDiv.is(':hidden'));
        });
    });
    */
    //------------------------------------------------------------------
    //---------------------------------------------------------------------------------
    // admin shortcode copy button - load only if button available
    const ter_kal_copyButton = document.getElementById('ter-kal-copy-button');
    if (ter_kal_copyButton) {
        const ter_kal_shortcodeText = document.getElementById('ter-kal-copyable-shortcode');
        ter_kal_copyButton.addEventListener('click', function (e) {
            e.preventDefault();
            const textToCopy = ter_kal_shortcodeText.textContent.trim();
            const originalText = ter_kal_copyButton.textContent;

            if (navigator.clipboard && window.isSecureContext) {
                navigator.clipboard.writeText(textToCopy);
            } else {
                // Fallback for older browsers
                const tempInput = document.createElement('input');
                tempInput.value = textToCopy;
                document.body.appendChild(tempInput);
                tempInput.select();
                document.execCommand('copy');
                document.body.removeChild(tempInput);
            }

            // Provide feedback to the user
            ter_kal_copyButton.textContent = 'Copied!';
            setTimeout(function () {
                ter_kal_copyButton.textContent = originalText;
            }, 3000);
        });
    }
    //---------------------------------------------------------------------------------
    //---------------------------------------------------------------------------------
    //});
})(jQuery);
//---------------------------------------------------------------------------------