<?php

if (!defined('ABSPATH')) {
    exit;
}

$user_id = get_current_user_id();
$banner_dismissed = get_user_meta($user_id, 'aieo_banner_dismissed', true);

if ($banner_dismissed) {
    return;
}
?>

<!-- Rotating Professional Setup Banner - Cycles through 5 different messages every 20 seconds -->
<style>
.aieo-rotating-banner {
    position: relative;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 35px 30px;
    border-radius: 12px;
    margin: 25px 0;
    box-shadow: 0 8px 20px rgba(102, 126, 234, 0.35);
    overflow: hidden;
    min-height: 320px;
}

.aieo-banner-slide {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    padding: 35px 30px;
    box-sizing: border-box;
    opacity: 0;
    transition: opacity 1s ease-in-out;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    pointer-events: none;
    z-index: 1;
}

.aieo-banner-slide.active {
    opacity: 1;
    position: relative;
    pointer-events: auto;
    z-index: 10;
}

.aieo-banner-slide h3 {
    margin: 0 0 15px 0;
    font-size: 26px;
    font-weight: 700;
    line-height: 1.3;
    color: #ffd97d;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.aieo-banner-slide p {
    font-size: 16px;
    line-height: 1.6;
    margin: 0 0 20px 0;
    opacity: 0.95;
}

.aieo-banner-features {
    background: rgba(255, 255, 255, 0.15);
    padding: 20px;
    border-radius: 8px;
    margin: 20px 0;
    margin-right: 0;
    backdrop-filter: blur(10px);
}

.aieo-banner-features-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 15px;
}

.aieo-banner-feature {
    font-size: 14px;
}

.aieo-banner-feature strong {
    display: block;
    margin-bottom: 5px;
    font-size: 15px;
}

.aieo-banner-feature small {
    opacity: 0.9;
    line-height: 1.4;
}

.aieo-banner-cta-section {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    flex-wrap: wrap;
    margin-top: 20px;
    margin-right: 0;
    position: relative;
    z-index: 50;
}

.aieo-banner-pricing {
    flex: 0 0 auto;
}

.aieo-banner-pricing-label {
    font-size: 13px;
    opacity: 0.9;
    margin-bottom: 5px;
}

.aieo-banner-pricing-amount {
    font-size: 32px;
    font-weight: 700;
    line-height: 1;
}

.aieo-banner-pricing-note {
    font-size: 12px;
    opacity: 0.8;
    margin-top: 5px;
}

.aieo-banner-cta-button {
    display: inline-block;
    background: white;
    color: #667eea;
    padding: 16px 40px;
    border-radius: 8px;
    text-decoration: none;
    font-weight: 700;
    font-size: 17px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.25);
    transition: all 0.3s ease;
    text-align: center;
    position: relative;
    z-index: 100;
    cursor: pointer;
}

.aieo-banner-cta-button:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3);
    color: #5568d3;
    text-decoration: none;
}

.aieo-banner-testimonial {
    margin-top: 20px;
    padding-top: 20px;
    border-top: 1px solid rgba(255, 255, 255, 0.2);
    font-size: 14px;
    font-style: italic;
    opacity: 0.95;
}

.aieo-banner-list {
    list-style: none;
    padding: 0;
    margin: 15px 0;
}

.aieo-banner-list li {
    padding: 8px 0;
    padding-left: 25px;
    position: relative;
    font-size: 15px;
}

.aieo-banner-list li:before {
    content: "✓";
    position: absolute;
    left: 0;
    font-weight: bold;
    font-size: 18px;
}

.aieo-banner-indicators {
    position: absolute;
    bottom: 15px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 8px;
    z-index: 10;
}

.aieo-banner-indicator {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.4);
    cursor: pointer;
    transition: all 0.3s ease;
}

.aieo-banner-indicator.active {
    background: white;
    width: 24px;
    border-radius: 4px;
}

.aieo-banner-comparison {
    background: rgba(0, 0, 0, 0.15);
    padding: 12px 20px;
    border-radius: 6px;
    margin: 15px 0;
    font-size: 14px;
}

.aieo-banner-comparison strong {
    font-size: 15px;
}

.aieo-banner-close {
    position: absolute;
    top: 15px;
    right: 15px;
    width: 32px;
    height: 32px;
    background: rgba(255, 255, 255, 0.2);
    border: none;
    border-radius: 50%;
    color: white;
    font-size: 20px;
    line-height: 1;
    cursor: pointer;
    transition: all 0.3s ease;
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
}

.aieo-banner-close:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: rotate(90deg);
}

.aieo-banner-close:focus {
    outline: 2px solid rgba(255, 255, 255, 0.5);
    outline-offset: 2px;
}

@media (max-width: 768px) {
    .aieo-rotating-banner {
        padding: 25px 20px;
        min-height: 400px;
    }

    .aieo-banner-slide h3 {
        font-size: 22px;
    }

    .aieo-banner-cta-section {
        flex-direction: column;
        align-items: stretch;
    }

    .aieo-banner-cta-button {
        width: 100%;
    }

    .aieo-banner-features-grid {
        grid-template-columns: 1fr;
    }
}
</style>

<div class="aieo-rotating-banner" id="aieoRotatingBanner">
    <!-- Close button -->
    <button class="aieo-banner-close" id="aieoBannerClose" aria-label="<?php esc_attr_e('Dismiss banner', 'ai-eshop-optimizer'); ?>" title="<?php esc_attr_e('Dismiss this banner', 'ai-eshop-optimizer'); ?>">
        ×
    </button>

    <!-- Slide 0: Training Video Promotion -->
    <div class="aieo-banner-slide active" data-slide="0">
        <div>
            <h3><?php esc_html_e('🎓 Master AI eShop Optimizer in 90 Minutes', 'ai-eshop-optimizer'); ?></h3>
            <p><strong><?php esc_html_e('Complete video training that covers everything you need to know.', 'ai-eshop-optimizer'); ?></strong> <?php esc_html_e('Learn setup, configuration, and optimization strategies from the experts who built the plugin.', 'ai-eshop-optimizer'); ?></p>

            <div class="aieo-banner-features">
                <div style="font-weight: 600; margin-bottom: 12px; font-size: 16px;"><?php esc_html_e('What you\'ll learn:', 'ai-eshop-optimizer'); ?></div>
                <ul class="aieo-banner-list">
                    <li><?php esc_html_e('Complete plugin setup and API configuration', 'ai-eshop-optimizer'); ?></li>
                    <li><?php esc_html_e('AI-powered recommendation strategies for maximum sales', 'ai-eshop-optimizer'); ?></li>
                    <li><?php esc_html_e('Advanced features: Chat integration, embeddings, and optimization', 'ai-eshop-optimizer'); ?></li>
                    <li><?php esc_html_e('Best practices for WooCommerce AI implementation', 'ai-eshop-optimizer'); ?></li>
                </ul>
            </div>
        </div>

        <div class="aieo-banner-cta-section">
            <div class="aieo-banner-pricing">
                <div class="aieo-banner-pricing-label"><?php esc_html_e('One-time investment:', 'ai-eshop-optimizer'); ?></div>
                <div class="aieo-banner-pricing-amount" style="font-size: 28px;">€49</div>
                <div class="aieo-banner-pricing-note"><?php esc_html_e('90 minutes • Lifetime access', 'ai-eshop-optimizer'); ?></div>
            </div>
            <a href="https://eshop-optimizer.com/service/training-video-of-ai-eshop-optimizer-usage?ref=plugin" class="aieo-banner-cta-button" target="_blank">
                <?php esc_html_e('Watch Training Video', 'ai-eshop-optimizer'); ?> →
            </a>
        </div>
    </div>

    <!-- Slide 1: Expert Partnership Approach -->
    <div class="aieo-banner-slide" data-slide="1">
        <div>
            <h3><?php esc_html_e('🚀 Fast-Track Your AI Implementation', 'ai-eshop-optimizer'); ?></h3>
            <p><strong><?php esc_html_e('Partner with our AI specialists for a personalized setup session.', 'ai-eshop-optimizer'); ?></strong> <?php esc_html_e('Get your store optimized in hours, not days.', 'ai-eshop-optimizer'); ?></p>

            <div class="aieo-banner-features">
                <div style="font-weight: 600; margin-bottom: 12px; font-size: 16px;"><?php esc_html_e('Why invest in expert setup?', 'ai-eshop-optimizer'); ?></div>
                <ul class="aieo-banner-list">
                    <li><?php esc_html_e('Skip the trial-and-error phase', 'ai-eshop-optimizer'); ?></li>
                    <li><?php esc_html_e('Learn advanced strategies tailored to your store', 'ai-eshop-optimizer'); ?></li>
                    <li><?php esc_html_e('Industry-specific best practices from eCommerce AI experts', 'ai-eshop-optimizer'); ?></li>
                    <li><?php esc_html_e('Get your first sales boost within 24 hours', 'ai-eshop-optimizer'); ?></li>
                </ul>
            </div>
        </div>

        <div class="aieo-banner-cta-section">
            <div class="aieo-banner-pricing">
                <div class="aieo-banner-pricing-label"><?php esc_html_e('Starting at:', 'ai-eshop-optimizer'); ?></div>
                <div class="aieo-banner-pricing-amount">€100/<?php esc_html_e('hour', 'ai-eshop-optimizer'); ?></div>
                <div class="aieo-banner-pricing-note"><?php esc_html_e('Average session: 2-3 hours', 'ai-eshop-optimizer'); ?></div>
            </div>
            <a href="https://eshop-optimizer.com/service/optimizer-setup?ref=plugin" class="aieo-banner-cta-button" target="_blank">
                <?php esc_html_e('Book Your Session', 'ai-eshop-optimizer'); ?> →
            </a>
        </div>
    </div>

    <!-- Slide 2: Time-Value Proposition -->
    <div class="aieo-banner-slide" data-slide="2">
        <div>
            <h3><?php esc_html_e('⚡ Premium Setup & Strategy Session', 'ai-eshop-optimizer'); ?></h3>
            <p><?php esc_html_e('Let our AI eCommerce specialists configure your optimal setup while training your team.', 'ai-eshop-optimizer'); ?></p>

            <div class="aieo-banner-features">
                <div style="font-weight: 600; margin-bottom: 15px; font-size: 16px;"><?php esc_html_e('You\'ll receive:', 'ai-eshop-optimizer'); ?></div>
                <div class="aieo-banner-features-grid">
                    <div class="aieo-banner-feature">
                        <strong><?php esc_html_e('Custom Configuration', 'ai-eshop-optimizer'); ?></strong>
                        <small><?php esc_html_e('Optimized for your product catalog', 'ai-eshop-optimizer'); ?></small>
                    </div>
                    <div class="aieo-banner-feature">
                        <strong><?php esc_html_e('Conversion Optimization', 'ai-eshop-optimizer'); ?></strong>
                        <small><?php esc_html_e('Data-driven recommendations', 'ai-eshop-optimizer'); ?></small>
                    </div>
                    <div class="aieo-banner-feature">
                        <strong><?php esc_html_e('Hands-On Training', 'ai-eshop-optimizer'); ?></strong>
                        <small><?php esc_html_e('For your team or clients', 'ai-eshop-optimizer'); ?></small>
                    </div>
                    <div class="aieo-banner-feature">
                        <strong><?php esc_html_e('Best Practice Guide', 'ai-eshop-optimizer'); ?></strong>
                        <small><?php esc_html_e('Ongoing reference documentation', 'ai-eshop-optimizer'); ?></small>
                    </div>
                </div>
            </div>
        </div>

        <div class="aieo-banner-cta-section">
            <div class="aieo-banner-pricing">
                <div class="aieo-banner-pricing-label"><?php esc_html_e('Investment:', 'ai-eshop-optimizer'); ?></div>
                <div class="aieo-banner-pricing-amount">€100/<?php esc_html_e('hour', 'ai-eshop-optimizer'); ?></div>
                <div class="aieo-banner-pricing-note"><?php esc_html_e('Complete setup in 2-3 hours', 'ai-eshop-optimizer'); ?></div>
            </div>
            <a href="https://eshop-optimizer.com/service/optimizer-setup?ref=plugin" class="aieo-banner-cta-button" target="_blank">
                <?php esc_html_e('Schedule Now', 'ai-eshop-optimizer'); ?> →
            </a>
        </div>
    </div>

    <!-- Slide 3: Competitive Advantage Angle -->
    <div class="aieo-banner-slide" data-slide="3">
        <div>
            <h3><?php esc_html_e('🎯 Professional Configuration Service', 'ai-eshop-optimizer'); ?></h3>
            <p><?php esc_html_e('Get enterprise-level AI optimization without the enterprise timeline or budget.', 'ai-eshop-optimizer'); ?></p>

            <div class="aieo-banner-comparison">
                <strong><?php esc_html_e('Compare:', 'ai-eshop-optimizer'); ?></strong> <?php esc_html_e('Similar AI tools charge €300-500/hour for professional setup.', 'ai-eshop-optimizer'); ?><br>
                <?php esc_html_e('Our expert service:', 'ai-eshop-optimizer'); ?> <strong style="font-size: 18px;">€100/<?php esc_html_e('hour', 'ai-eshop-optimizer'); ?></strong> — <?php esc_html_e('Same expertise, better value.', 'ai-eshop-optimizer'); ?>
            </div>

            <div class="aieo-banner-features">
                <div style="font-weight: 600; margin-bottom: 12px; font-size: 16px;"><?php esc_html_e('Ideal for:', 'ai-eshop-optimizer'); ?></div>
                <ul class="aieo-banner-list">
                    <li><?php esc_html_e('Agencies managing multiple client stores', 'ai-eshop-optimizer'); ?></li>
                    <li><?php esc_html_e('Merchants launching competitive AI-driven recommendations', 'ai-eshop-optimizer'); ?></li>
                    <li><?php esc_html_e('Teams wanting to maximize ROI from day one', 'ai-eshop-optimizer'); ?></li>
                    <li><?php esc_html_e('Businesses scaling their eCommerce operations', 'ai-eshop-optimizer'); ?></li>
                </ul>
            </div>
        </div>

        <div class="aieo-banner-cta-section">
            <div class="aieo-banner-pricing">
                <div class="aieo-banner-pricing-label"><?php esc_html_e('Professional setup:', 'ai-eshop-optimizer'); ?></div>
                <div class="aieo-banner-pricing-amount">€100/<?php esc_html_e('hour', 'ai-eshop-optimizer'); ?></div>
                <div class="aieo-banner-pricing-note"><?php esc_html_e('Save €200-400 vs. competitors', 'ai-eshop-optimizer'); ?></div>
            </div>
            <a href="https://eshop-optimizer.com/service/optimizer-setup?ref=plugin" class="aieo-banner-cta-button" target="_blank">
                <?php esc_html_e('Book Strategy Session', 'ai-eshop-optimizer'); ?> →
            </a>
        </div>
    </div>

    <!-- Slide 4: Knowledge Transfer Focus -->
    <div class="aieo-banner-slide" data-slide="4">
        <div>
            <h3><?php esc_html_e('💡 Expert-Led Implementation Workshop', 'ai-eshop-optimizer'); ?></h3>
            <p><strong><?php esc_html_e('Accelerate your learning curve', 'ai-eshop-optimizer'); ?></strong> <?php esc_html_e('with hands-on guidance from the team that built the AI engine.', 'ai-eshop-optimizer'); ?></p>

            <div class="aieo-banner-features">
                <div style="font-weight: 600; margin-bottom: 15px; font-size: 16px;"><?php esc_html_e('What makes this valuable:', 'ai-eshop-optimizer'); ?></div>
                <div class="aieo-banner-features-grid">
                    <div class="aieo-banner-feature">
                        <strong><?php esc_html_e('Development Team Access', 'ai-eshop-optimizer'); ?></strong>
                        <small><?php esc_html_e('Direct insights from the builders', 'ai-eshop-optimizer'); ?></small>
                    </div>
                    <div class="aieo-banner-feature">
                        <strong><?php esc_html_e('Repeatable Patterns', 'ai-eshop-optimizer'); ?></strong>
                        <small><?php esc_html_e('Solutions that work across clients', 'ai-eshop-optimizer'); ?></small>
                    </div>
                    <div class="aieo-banner-feature">
                        <strong><?php esc_html_e('Complex Integration Help', 'ai-eshop-optimizer'); ?></strong>
                        <small><?php esc_html_e('Get answers to technical questions', 'ai-eshop-optimizer'); ?></small>
                    </div>
                    <div class="aieo-banner-feature">
                        <strong><?php esc_html_e('Setup Documentation', 'ai-eshop-optimizer'); ?></strong>
                        <small><?php esc_html_e('Your optimized configuration saved', 'ai-eshop-optimizer'); ?></small>
                    </div>
                </div>
            </div>

            <div style="margin-top: 15px; padding: 12px 15px; background: rgba(255,255,255,0.1); border-radius: 6px; font-size: 14px;">
                <strong><?php esc_html_e('Perfect for agencies', 'ai-eshop-optimizer'); ?></strong> <?php esc_html_e('building repeatable client solutions.', 'ai-eshop-optimizer'); ?>
            </div>
        </div>

        <div class="aieo-banner-cta-section">
            <div class="aieo-banner-pricing">
                <div class="aieo-banner-pricing-label"><?php esc_html_e('1-on-1 Workshop:', 'ai-eshop-optimizer'); ?></div>
                <div class="aieo-banner-pricing-amount">€100/<?php esc_html_e('hour', 'ai-eshop-optimizer'); ?></div>
            </div>
            <a href="https://eshop-optimizer.com/service/optimizer-setup?ref=plugin" class="aieo-banner-cta-button" target="_blank">
                <?php esc_html_e('Book Your Workshop', 'ai-eshop-optimizer'); ?> →
            </a>
        </div>
    </div>

    <!-- Slide 5: Confidence Builder -->
    <div class="aieo-banner-slide" data-slide="5">
        <div>
            <h3><?php esc_html_e('🤝 Personalized Configuration & Training', 'ai-eshop-optimizer'); ?></h3>
            <p><?php esc_html_e('Even the most sophisticated AI tools benefit from expert calibration to your specific business model.', 'ai-eshop-optimizer'); ?> <strong><?php esc_html_e('Let us fine-tune your setup for maximum performance.', 'ai-eshop-optimizer'); ?></strong></p>

            <div class="aieo-banner-testimonial" style="margin-top: 15px; margin-bottom: 15px;">
                "<?php esc_html_e('Saved us 20+ hours of testing. Worth every euro. The strategies on embedding models and deduplication alone paid for the session.', 'ai-eshop-optimizer'); ?>"<br>
                <strong>— <?php esc_html_e('WooCommerce Development Agency', 'ai-eshop-optimizer'); ?></strong>
            </div>

            <div class="aieo-banner-testimonial" style="border-top: none; padding-top: 0;">
                "<?php esc_html_e('Got advanced configuration insights we wouldn\'t have discovered on our own. Now we\'re replicating this across 12 client stores.', 'ai-eshop-optimizer'); ?>"<br>
                <strong>— <?php esc_html_e('eCommerce Store Owner & Consultant', 'ai-eshop-optimizer'); ?></strong>
            </div>
        </div>

        <div class="aieo-banner-cta-section">
            <div class="aieo-banner-pricing">
                <div class="aieo-banner-pricing-label"><?php esc_html_e('Optional Expert Setup:', 'ai-eshop-optimizer'); ?></div>
                <div class="aieo-banner-pricing-amount">€100/<?php esc_html_e('hour', 'ai-eshop-optimizer'); ?></div>
                <div class="aieo-banner-pricing-note"><?php esc_html_e('No commitment required', 'ai-eshop-optimizer'); ?></div>
            </div>
            <a href="https://eshop-optimizer.com/service/optimizer-setup?ref=plugin" class="aieo-banner-cta-button" target="_blank">
                <?php esc_html_e('Learn More', 'ai-eshop-optimizer'); ?> →
            </a>
        </div>
    </div>

    <!-- Slide Indicators -->
    <div class="aieo-banner-indicators">
        <div class="aieo-banner-indicator active" data-indicator="0"></div>
        <div class="aieo-banner-indicator" data-indicator="1"></div>
        <div class="aieo-banner-indicator" data-indicator="2"></div>
        <div class="aieo-banner-indicator" data-indicator="3"></div>
        <div class="aieo-banner-indicator" data-indicator="4"></div>
        <div class="aieo-banner-indicator" data-indicator="5"></div>
    </div>
</div>

<script>
(function() {
    let currentSlide = 0;
    const slides = document.querySelectorAll('.aieo-banner-slide');
    const indicators = document.querySelectorAll('.aieo-banner-indicator');
    const totalSlides = slides.length;
    let autoRotateInterval;

    function showSlide(index) {
        // Remove active class from all slides and indicators
        slides.forEach(slide => slide.classList.remove('active'));
        indicators.forEach(indicator => indicator.classList.remove('active'));

        // Add active class to current slide and indicator
        slides[index].classList.add('active');
        indicators[index].classList.add('active');

        currentSlide = index;
    }

    function nextSlide() {
        let next = (currentSlide + 1) % totalSlides;
        showSlide(next);
    }

    function startAutoRotate() {
        // Clear any existing interval
        if (autoRotateInterval) {
            clearInterval(autoRotateInterval);
        }
        // Start new interval - rotate every 20 seconds
        autoRotateInterval = setInterval(nextSlide, 20000);
    }

    // Add click handlers to indicators
    indicators.forEach((indicator, index) => {
        indicator.addEventListener('click', function() {
            showSlide(index);
            // Restart auto-rotation after manual click
            startAutoRotate();
        });
    });

    // Pause rotation on hover, resume on mouse leave
    const banner = document.getElementById('aieoRotatingBanner');
    banner.addEventListener('mouseenter', function() {
        if (autoRotateInterval) {
            clearInterval(autoRotateInterval);
        }
    });

    banner.addEventListener('mouseleave', function() {
        startAutoRotate();
    });

    // Close button handler
    const closeButton = document.getElementById('aieoBannerClose');
    if (closeButton) {
        closeButton.addEventListener('click', function() {
            // Clear rotation interval
            if (autoRotateInterval) {
                clearInterval(autoRotateInterval);
            }

            // Fade out the banner
            banner.style.transition = 'opacity 0.5s ease, max-height 0.5s ease, margin 0.5s ease, padding 0.5s ease';
            banner.style.opacity = '0';
            banner.style.maxHeight = '0';
            banner.style.marginTop = '0';
            banner.style.marginBottom = '0';
            banner.style.paddingTop = '0';
            banner.style.paddingBottom = '0';

            // Remove from DOM after animation
            setTimeout(function() {
                banner.style.display = 'none';
            }, 500);

            // Save dismissal preference via AJAX
            if (typeof ajaxurl !== 'undefined') {
                const formData = new FormData();
                formData.append('action', 'aieo_dismiss_banner');
                formData.append('nonce', '<?php echo esc_js(wp_create_nonce('aieo_dismiss_banner')); ?>');

                fetch(ajaxurl, {
                    method: 'POST',
                    body: formData
                }).catch(function(error) {
                    console.error('Error saving banner dismissal:', error);
                });
            }
        });
    }

    // Start auto-rotation
    startAutoRotate();
})();
</script>
