/**
 * License Page JavaScript for BotFend Pro
 *
 * Handles copy to clipboard, confirmation dialogs, and AJAX interactions.
 *
 * @package BotFend\Assets\JS
 * @since 4.9.0
 */

(function($) {
    'use strict';

    $(document).ready(function() {

        /**
         * Copy license key to clipboard
         */
        $('.botfend-copy-key').on('click', function(e) {
            e.preventDefault();
            
            var $btn = $(this);
            var licenseKey = $btn.data('key');
            var $temp = $('<input>');
            
            $('body').append($temp);
            $temp.val(licenseKey).select();
            
            try {
                document.execCommand('copy');
                $btn.html('<span class="dashicons dashicons-yes"></span>');
                
                setTimeout(function() {
                    $btn.html('<span class="dashicons dashicons-clipboard"></span>');
                }, 2000);
            } catch (err) {
                alert(botfendLicense.i18n.copyError);
            }
            
            $temp.remove();
        });

        /**
         * Confirm deactivation
         */
        $('.botfend-deactivate-btn').on('click', function(e) {
            if (!confirm(botfendLicense.i18n.deactivateConfirm)) {
                e.preventDefault();
                return false;
            }
            return true;
        });

        /**
         * Auto-focus license input on inactive page
         */
        if ($('.botfend-license-card.inactive').length) {
            $('.license-input').focus();
        }

    });

})(jQuery);