/**
 * Admin Dashboard JavaScript for Subscription System
 *
 * @package    Subscription_System
 * @subpackage Subscription_System/admin/js
 */

(function( $ ) {
    'use strict';

    /**
     * Copy shortcode functionality
     */
    function initCopyShortcode() {
        $('.copy-shortcode').on('click', function() {
            var shortcode = $(this).data('shortcode');
            
            // Create a temporary textarea to copy the shortcode
            var temp = $('<textarea>');
            $('body').append(temp);
            temp.val(shortcode).select();
            document.execCommand('copy');
            temp.remove();
            
            var button = $(this);
            var originalText = button.text();
            button.text('Copied!');
            button.addClass('button-primary');
            
            setTimeout(function() {
                button.text(originalText);
                button.removeClass('button-primary');
            }, 2000);
        });
    }

    /**
     * Initialize dashboard functionality
     */
    function initDashboard() {
        // Add loading states to action buttons
        $('.action-card .button').on('click', function() {
            var button = $(this);
            var originalText = button.text();
            
            button.text('Loading...');
            button.prop('disabled', true);
            
            // Re-enable after a short delay (in case of quick navigation)
            setTimeout(function() {
                button.text(originalText);
                button.prop('disabled', false);
            }, 3000);
        });

        // Add hover effects to stat cards
        $('.stat-card').hover(
            function() {
                $(this).find('.stat-icon .dashicons').addClass('animated');
            },
            function() {
                $(this).find('.stat-icon .dashicons').removeClass('animated');
            }
        );
    }

    /**
     * Document ready
     */
    $(document).ready(function() {
        initCopyShortcode();
        initDashboard();
    });

})( jQuery ); 