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

(function( $ ) {
    'use strict';

    /**
     * Initialize help page functionality
     */
    function initHelpPage() {
        // Copy shortcode functionality
        $('.copy-shortcode').on('click', function() {
            var shortcode = $(this).data('shortcode');
            var textarea = $(this).siblings('textarea')[0];
            
            if (textarea) {
                textarea.select();
                textarea.setSelectionRange(0, 99999);
                
                try {
                    document.execCommand('copy');
                    showCopySuccess($(this));
                } catch (err) {
                    console.error('Failed to copy shortcode:', err);
                    showCopyError($(this));
                }
            }
        });
    }

    /**
     * Show copy success feedback
     */
    function showCopySuccess(button) {
        var originalText = button.text();
        button.text(subs_sys_help_vars.copied_text);
        button.addClass('button-primary');
        
        setTimeout(function() {
            button.text(originalText);
            button.removeClass('button-primary');
        }, 2000);
    }

    /**
     * Show copy error feedback
     */
    function showCopyError(button) {
        var originalText = button.text();
        button.text(subs_sys_help_vars.copy_error_text);
        button.addClass('button-secondary');
        
        setTimeout(function() {
            button.text(originalText);
            button.removeClass('button-secondary');
        }, 2000);
    }

    /**
     * Smooth scroll to sections
     */
    function initSmoothScroll() {
        $('a[href^="#"]').on('click', function(e) {
            e.preventDefault();
            
            var target = $(this.getAttribute('href'));
            if (target.length) {
                $('html, body').animate({
                    scrollTop: target.offset().top - 50
                }, 500);
            }
        });
    }

    /**
     * Add animation to feature list items
     */
    function initFeatureAnimations() {
        $('.feature-list li').each(function(index) {
            $(this).css('animation-delay', (index * 0.1) + 's');
            $(this).addClass('fade-in');
        });
    }

    /**
     * Document ready
     */
    $(document).ready(function() {
        initHelpPage();
        initSmoothScroll();
        initFeatureAnimations();
    });

})( jQuery ); 