<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Webinar Demo - FastOpp</title>
    <link rel="icon" type="image/x-icon" href="{{ url_for('static', path='/favicon.ico') }}">
    <script src="https://unpkg.com/htmx.org@2.0.6"></script>
    <script src="https://unpkg.com/alpinejs@3.x.x/dist/cdn.min.js" defer></script>
    <script src="https://cdn.tailwindcss.com"></script>
    <script>
        tailwind.config = {
            theme: {
                extend: {
                    colors: {
                        'ai-blue': '#3B82F6',
                        'ai-purple': '#8B5CF6'
                    }
                }
            }
        }
    </script>
</head>
<body class="bg-gradient-to-br from-gray-50 to-blue-50 min-h-screen">
    <div class="min-h-screen flex flex-col">
        {% include 'partials/header.html' %}

        <!-- Hero Section -->
        <section class="relative overflow-hidden bg-gradient-to-r from-ai-blue to-ai-purple text-white py-20">
            <div class="absolute inset-0 bg-black opacity-10"></div>
            <div class="relative max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 text-center">
                <h1 class="text-5xl md:text-6xl font-bold mb-6">
                    Amazing Webinar Community
                </h1>
                <p class="text-xl md:text-2xl mb-8 opacity-90">
                    Meet the incredible professionals who joined our latest webinar
                </p>
                <div class="flex justify-center space-x-4">
                    <div class="bg-white bg-opacity-20 rounded-full px-6 py-2">
                        <span class="text-lg font-semibold">5</span> Attendees
                    </div>
                    <div class="bg-white bg-opacity-20 rounded-full px-6 py-2">
                        <span class="text-lg font-semibold">5</span> Webinars
                    </div>
                </div>
            </div>
        </section>

        <!-- Main Content -->
        <main class="flex-grow">
            <div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 py-12" x-data="webinarDemo()" x-init="console.log('Alpine.js working')">
                
                <!-- Webinar Overview -->
                <div class="bg-white rounded-2xl shadow-xl p-8 mb-12">
                    <div class="text-center mb-8">
                        <div class="w-20 h-20 bg-gradient-to-br from-ai-blue to-ai-purple rounded-full flex items-center justify-center mx-auto mb-6">
                            <svg class="w-10 h-10 text-white" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 10l4.553-2.276A1 1 0 0121 8.618v6.764a1 1 0 01-1.447.894L15 14M5 18h8a2 2 0 002-2V8a2 2 0 00-2-2H5a2 2 0 00-2 2v8a2 2 0 002 2z"></path>
                            </svg>
                        </div>
                        <h2 class="text-3xl font-bold text-gray-900 mb-4">Latest Webinar Highlights</h2>
                        <p class="text-xl text-gray-600 max-w-3xl mx-auto">
                            Our community of professionals shared insights, asked great questions, and built connections that will drive innovation forward.
                        </p>
                    </div>

                    <!-- Webinar Stats -->
                    <div class="grid md:grid-cols-3 gap-8 mb-8">
                        <div class="text-center">
                            <div class="text-4xl font-bold text-ai-blue mb-2" x-text="stats.engagement">95%</div>
                            <div class="text-gray-600">Engagement Rate</div>
                        </div>
                        <div class="text-center">
                            <div class="text-4xl font-bold text-ai-purple mb-2" x-text="stats.questions">47</div>
                            <div class="text-gray-600">Questions Asked</div>
                        </div>
                        <div class="text-center">
                            <div class="text-4xl font-bold text-green-600 mb-2" x-text="stats.followup">89%</div>
                            <div class="text-gray-600">Follow-up Interest</div>
                        </div>
                    </div>
                </div>

                <!-- Attendees Grid -->
                <div class="mb-12">
                    <h3 class="text-2xl font-bold text-gray-900 mb-8 text-center">Meet Our Amazing Attendees</h3>
                    <div id="attendeesContainer" 
                         hx-get="/api/webinar-attendees" 
                         hx-trigger="load"
                         hx-target="this"
                         hx-swap="innerHTML">
                        <!-- Attendees will be loaded here -->
                        <div class="text-center py-8">
                            <p class="text-gray-500">Loading attendees...</p>
                        </div>
                    </div>
                    

                </div>

                <!-- Next Steps Section -->
                <div class="bg-white rounded-2xl shadow-xl p-8">
                    <h3 class="text-2xl font-bold text-gray-900 mb-6 text-center">What's Next?</h3>
                    <div class="grid md:grid-cols-2 lg:grid-cols-3 gap-8">
                        
                        <!-- Connect with Peers -->
                        <div class="text-center p-6 rounded-xl bg-gradient-to-br from-blue-50 to-blue-100">
                            <div class="w-16 h-16 bg-ai-blue rounded-full flex items-center justify-center mx-auto mb-4">
                                <svg class="w-8 h-8 text-white" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M17 20h5v-2a3 3 0 00-5.356-1.857M17 20H7m10 0v-2c0-.656-.126-1.283-.356-1.857M7 20H2v-2a3 3 0 015.356-1.857M7 20v-2c0-.656.126-1.283.356-1.857m0 0a5.002 5.002 0 019.288 0M15 7a3 3 0 11-6 0 3 3 0 016 0zm6 3a2 2 0 11-4 0 2 2 0 014 0zM7 10a2 2 0 11-4 0 2 2 0 014 0z"></path>
                                </svg>
                            </div>
                            <h4 class="text-xl font-semibold text-gray-900 mb-3">Connect with Peers</h4>
                            <p class="text-gray-600 mb-4">Network with fellow attendees and share insights from the webinar.</p>
                            <button class="bg-ai-blue text-white px-6 py-2 rounded-lg hover:bg-blue-700 transition-colors">
                                Join Community
                            </button>
                        </div>

                        <!-- Access Resources -->
                        <div class="text-center p-6 rounded-xl bg-gradient-to-br from-purple-50 to-purple-100">
                            <div class="w-16 h-16 bg-ai-purple rounded-full flex items-center justify-center mx-auto mb-4">
                                <svg class="w-8 h-8 text-white" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 6.253v13m0-13C10.832 5.477 9.246 5 7.5 5S4.168 5.477 3 6.253v13C4.168 18.477 5.754 18 7.5 18s3.332.477 4.5 1.253m0-13C13.168 5.477 14.754 5 16.5 5c1.746 0 3.332.477 4.5 1.253v13C19.832 18.477 18.246 18 16.5 18c-1.746 0-3.332.477-4.5 1.253"></path>
                                </svg>
                            </div>
                            <h4 class="text-xl font-semibold text-gray-900 mb-3">Access Resources</h4>
                            <p class="text-gray-600 mb-4">Download slides, recordings, and additional materials from the session.</p>
                            <button class="bg-ai-purple text-white px-6 py-2 rounded-lg hover:bg-purple-700 transition-colors">
                                Get Resources
                            </button>
                        </div>

                        <!-- Upcoming Events -->
                        <div class="text-center p-6 rounded-xl bg-gradient-to-br from-green-50 to-green-100">
                            <div class="w-16 h-16 bg-green-500 rounded-full flex items-center justify-center mx-auto mb-4">
                                <svg class="w-8 h-8 text-white" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M8 7V3m8 4V3m-9 8h10M5 21h14a2 2 0 002-2V7a2 2 0 00-2-2H5a2 2 0 00-2 2v12a2 2 0 002 2z"></path>
                                </svg>
                            </div>
                            <h4 class="text-xl font-semibold text-gray-900 mb-3">Upcoming Events</h4>
                            <p class="text-gray-600 mb-4">Register for our next webinars and continue your learning journey.</p>
                            <button class="bg-green-500 text-white px-6 py-2 rounded-lg hover:bg-green-600 transition-colors">
                                View Events
                            </button>
                        </div>
                    </div>
                </div>
            </div>
        </main>

        <!-- Footer -->
        {% include 'partials/footer.html' %}
    </div>

    <script>
        function webinarDemo() {
            return {
                attendeeCount: 0,
                webinarCount: 0,
                stats: {
                    engagement: '95%',
                    questions: 47,
                    followup: '89%'
                },
                init() {
                    console.log('Alpine.js component initialized');
                    // Set initial values immediately
                    this.attendeeCount = 5;
                    this.webinarCount = 5;
                    this.databaseUnavailable = false;
                    
                    // Then try to load real data
                    this.loadAttendeeCounts();
                },
                loadAttendeeCounts() {
                    console.log('Loading attendee counts...');
                    fetch('/api/webinar-attendees')
                        .then(response => {
                            console.log('Response status:', response.status);
                            return response.json();
                        })
                        .then(data => {
                            console.log('Received data:', data);
                            
                            if (data.attendees && data.attendees.length > 0) {
                                const attendeeCount = data.attendees.length;
                                const uniqueWebinars = new Set(data.attendees.map(a => a.webinar_title)).size;
                                
                                console.log(`Found ${attendeeCount} attendees and ${uniqueWebinars} webinars`);
                                
                                // Update counters with real data
                                this.attendeeCount = attendeeCount;
                                this.webinarCount = uniqueWebinars;
                                
                                // Trigger HTMX to load the attendees display
                                setTimeout(() => {
                                    this.triggerHtmxLoad();
                                }, 100);
                            } else {
                                // Show database unavailable message and prevent HTMX
                                this.showDatabaseUnavailableMessage();
                                this.databaseUnavailable = true;
                            }
                        })
                        .catch(error => {
                            console.error('Error loading attendee data:', error);
                            this.showDatabaseUnavailableMessage();
                            this.databaseUnavailable = true;
                        });
                },
                
                triggerHtmxLoad() {
                    const container = document.getElementById('attendeesContainer');
                    if (container && container.innerHTML.includes('Loading attendees')) {
                        console.log('Manually triggering HTMX request');
                        htmx.trigger(container, 'load');
                    }
                },
                
                showDatabaseUnavailableMessage() {
                    // Show a user-friendly message when database is unavailable
                    const message = `
                        <div class="bg-yellow-50 border-l-4 border-yellow-400 p-4 mb-6">
                            <div class="flex">
                                <div class="flex-shrink-0">
                                    <svg class="h-5 w-5 text-yellow-400" viewBox="0 0 20 20" fill="currentColor">
                                        <path fill-rule="evenodd" d="M8.257 3.099c.765-1.36 2.722-1.36 3.486 0l5.58 9.92c.75 1.334-.213 2.98-1.742 2.98H4.42c-1.53 0-2.493-1.646-1.743-2.98l5.58-9.92zM11 13a1 1 0 11-2 0 1 1 0 012 0zm-1-8a1 1 0 00-1 1v3a1 1 0 002 0V6a1 1 0 00-1-1z" clip-rule="evenodd" />
                                    </svg>
                                </div>
                                <div class="ml-3">
                                    <p class="text-sm text-yellow-700">
                                        <strong>Database Unavailable:</strong> Unable to load attendee data. This demo requires a properly configured database connection.
                                    </p>
                                </div>
                            </div>
                        </div>
                    `;
                    
                    // Insert the message in the attendees container
                    const container = document.getElementById('attendeesContainer');
                    if (container) {
                        container.innerHTML = message;
                    }
                }
            }
        }

        // HTMX is now handled by the server returning HTML directly
        
        // Ensure HTMX loads attendees when the page is ready (only if database is available)
        document.addEventListener('DOMContentLoaded', function() {
            setTimeout(() => {
                // Check if database is unavailable by looking for the warning message
                const container = document.getElementById('attendeesContainer');
                if (container && !container.innerHTML.includes('Database Unavailable') && container.innerHTML.includes('Loading attendees')) {
                    console.log('DOM ready - triggering HTMX request');
                    htmx.trigger(container, 'load');
                }
            }, 1000);
        });

        function getWebinarIcon(webinarTitle) {
            const icons = {
                'FastAPI': '<svg class="w-5 h-5 text-blue-600" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13 10V3L4 14h7v7l9-11h-7z"></path></svg>',
                'Database': '<svg class="w-5 h-5 text-purple-600" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 7v10c0 2.21 3.582 4 8 4s8-1.79 8-4V7M4 7c0 2.21 3.582 4 8 4s8-1.79 8-4M4 7c0-2.21 3.582-4 8-4s8 1.79 8 4"></path></svg>',
                'Security': '<svg class="w-5 h-5 text-red-600" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12l2 2 4-4m5.618-4.016A11.955 11.955 0 0112 2.944a11.955 11.955 0 01-8.618 3.04A12.02 12.02 0 003 9c0 5.591 3.824 10.29 9 11.622 5.176-1.332 9-6.03 9-11.622 0-1.042-.133-2.052-.382-3.016z"></path></svg>',
                'Production': '<svg class="w-5 h-5 text-green-600" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 12h14M5 12a2 2 0 01-2-2V6a2 2 0 012-2h14a2 2 0 012 2v4a2 2 0 01-2 2M5 12a2 2 0 00-2 2v4a2 2 0 002 2h14a2 2 0 002-2v-4a2 2 0 00-2-2m-2-4h.01M17 16h.01"></path></svg>',
                'Testing': '<svg class="w-5 h-5 text-yellow-600" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 5H7a2 2 0 00-2 2v10a2 2 0 002 2h8a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2"></path></svg>',
                'Performance': '<svg class="w-5 h-5 text-indigo-600" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13 10V3L4 14h7v7l9-11h-7z"></path></svg>',
                'Authentication': '<svg class="w-5 h-5 text-pink-600" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 7a2 2 0 012 2m4 0a6 6 0 01-7.743 5.743L11 17H9v2H7v2H4a1 1 0 01-1-1v-2.586a1 1 0 01.293-.707l5.964-5.964A6 6 0 1121 9z"></path></svg>'
            };
            
            for (const [key, icon] of Object.entries(icons)) {
                if (webinarTitle.includes(key)) {
                    return icon;
                }
            }
            
            // Default icon
            return '<svg class="w-5 h-5 text-gray-600" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 10l4.553-2.276A1 1 0 0121 8.618v6.764a1 1 0 01-1.447.894L15 14M5 18h8a2 2 0 002-2V8a2 2 0 00-2-2H5a2 2 0 00-2 2v8a2 2 0 002 2z"></path></svg>';
        }
    </script>
</body>
</html> 