;(function($) {
    'use strict';

    /**
     * Initialize Interactive Promo Widget
     */
    function initInteractivePromo($scope) {
        // 3D Tilt Effect for Layout 5
        const $promoLayout5 = $scope.find('.unlockafe-promo-layout-5');
        
        if ($promoLayout5.length > 0) {
            $promoLayout5.each(function() {
                const $promo = $(this);
                const $wrapper = $promo.find('.promo-wrapper');
                
                $promo.on('mousemove', function(e) {
                    const rect = this.getBoundingClientRect();
                    const x = e.clientX - rect.left;
                    const y = e.clientY - rect.top;
                    
                    const centerX = rect.width / 2;
                    const centerY = rect.height / 2;
                    
                    const rotateX = (y - centerY) / 20;
                    const rotateY = (centerX - x) / 20;
                    
                    $wrapper.css({
                        'transform': `perspective(1000px) rotateX(${rotateX}deg) rotateY(${rotateY}deg)`
                    });
                });
                
                $promo.on('mouseleave', function() {
                    $wrapper.css({
                        'transform': 'perspective(1000px) rotateX(0) rotateY(0)'
                    });
                });
            });
        }

        // Parallax Effect (optional enhancement)
        const $promoItems = $scope.find('.unlockafe-interactive-promo');
        
        if ($promoItems.length > 0 && !$promoItems.hasClass('unlockafe-promo-layout-5')) {
            $(window).on('scroll.promo', function() {
                const scrollTop = $(window).scrollTop();
                
                $promoItems.each(function() {
                    const $item = $(this);
                    const itemTop = $item.offset().top;
                    const itemHeight = $item.outerHeight();
                    const windowHeight = $(window).height();
                    
                    if (itemTop < scrollTop + windowHeight && itemTop + itemHeight > scrollTop) {
                        const scrolled = scrollTop - itemTop;
                        const parallaxSpeed = 0.3;
                        const $image = $item.find('.promo-image');
                        
                        if ($image.length) {
                            $image.css({
                                'transform': `translateY(${scrolled * parallaxSpeed}px) scale(1.05)`
                            });
                        }
                    }
                });
            });
        }
    }

    // Initialize on Elementor frontend
    $(window).on('elementor/frontend/init', function() {
        elementorFrontend.hooks.addAction('frontend/element_ready/unlockafe-interactive-promo.default', function($scope) {
            initInteractivePromo($scope);
        });
    });

    // Also initialize on document ready (for non-Elementor pages)
    $(document).ready(function() {
        $('.elementor-widget-unlockafe-interactive-promo').each(function() {
            var $scope = $(this);
            initInteractivePromo($scope);
        });
    });

    // Cleanup on window resize
    $(window).on('resize', function() {
        $('.unlockafe-promo-layout-5 .promo-wrapper').css({
            'transform': 'perspective(1000px) rotateX(0) rotateY(0)'
        });
    });

})(jQuery);





