{% extends "base.html" %}

{% block title %}Forum{% endblock %}

{% block content %}

<!-- Hero -->
<section class="relative py-24 overflow-hidden">
    <div class="absolute inset-0 dot-grid opacity-30 pointer-events-none"></div>
    <div class="absolute top-0 left-1/2 -translate-x-1/2 w-[600px] h-[350px] pointer-events-none"
         style="background: radial-gradient(ellipse, rgba(92,184,44,0.1) 0%, transparent 70%); filter: blur(40px);"></div>

    <div class="relative max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 text-center">
        <div class="badge badge-accent mb-6">Community</div>
        <h1 class="text-5xl md:text-6xl font-extrabold mb-5 leading-tight" style="font-family: 'Syne', sans-serif; color: #f1f0ff;">
            Community <span class="gradient-text">Forum</span>
        </h1>
        <p class="text-lg max-w-xl mx-auto mb-10" style="color: #8b8ca8;">
            Connect with other developers, ask questions, share knowledge, and grow together.
        </p>

        <!-- Search -->
        <div class="max-w-md mx-auto relative">
            <input type="text"
                   placeholder="Search topics…"
                   class="input pl-11 py-3.5"
                   hx-get="{{ url_for('forum_search') }}"
                   hx-trigger="keyup changed delay:500ms"
                   hx-target="#search-results"
                   name="q">
            <svg class="w-4 h-4 absolute left-4 top-1/2 -translate-y-1/2 pointer-events-none" style="color: #6b6b8a;"
                 fill="none" stroke="currentColor" viewBox="0 0 24 24">
                <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z" />
            </svg>
        </div>
    </div>
</section>

<!-- Categories -->
<section class="py-16" style="background: #0a0a14;">
    <div class="max-w-5xl mx-auto px-4 sm:px-6 lg:px-8">

        <!-- Search results -->
        <div id="search-results" class="mb-6"></div>

        <!-- Categories -->
        <div class="mb-4 text-xs font-semibold tracking-widest uppercase" style="color: #6b6b8a; font-family: 'Syne', sans-serif;">Categories</div>

        {% if categories %}
        <div class="space-y-3">
            {% for category in categories %}
            <a href="{{ url_for('forum_category', slug=category.slug) }}"
               class="card-hover flex items-center gap-5 p-6 group block">
                <div class="w-11 h-11 rounded-xl flex items-center justify-center flex-shrink-0"
                     style="background: rgba(92,184,44,0.1); border: 1px solid rgba(92,184,44,0.2);">
                    <svg class="w-5 h-5 text-primary-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5" d="M17 8h2a2 2 0 012 2v6a2 2 0 01-2 2h-2v4l-4-4H9a1.994 1.994 0 01-1.414-.586m0 0L11 14h4a2 2 0 002-2V6a2 2 0 00-2-2H5a2 2 0 00-2 2v6a2 2 0 002 2h2v4l.586-.586z" />
                    </svg>
                </div>
                <div class="flex-grow min-w-0">
                    <h3 class="text-base font-bold mb-0.5 group-hover:text-primary-300 transition-colors" style="font-family: 'Syne', sans-serif; color: #f1f0ff;">
                        {{ category.name }}
                    </h3>
                    <p class="text-sm truncate" style="color: #8b8ca8;">{{ category.description }}</p>
                </div>
                <div class="flex-shrink-0 text-right">
                    <div class="text-sm font-semibold" style="color: #e8e6f0;">{{ category.topics.count() }}</div>
                    <div class="text-xs" style="color: #6b6b8a;">topics</div>
                </div>
                <svg class="w-4 h-4 flex-shrink-0 text-primary-500 opacity-0 group-hover:opacity-100 transition-opacity" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M17 8l4 4m0 0l-4 4m4-4H3"/>
                </svg>
            </a>
            {% endfor %}
        </div>
        {% else %}
        <div class="text-center py-16">
            <div class="w-14 h-14 rounded-xl flex items-center justify-center mx-auto mb-4"
                 style="background: rgba(92,184,44,0.1); border: 1px solid rgba(92,184,44,0.2);">
                <svg class="w-7 h-7 text-primary-500" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5" d="M17 8h2a2 2 0 012 2v6a2 2 0 01-2 2h-2v4l-4-4H9a1.994 1.994 0 01-1.414-.586m0 0L11 14h4a2 2 0 002-2V6a2 2 0 00-2-2H5a2 2 0 00-2 2v6a2 2 0 002 2h2v4l.586-.586z" />
                </svg>
            </div>
            <h3 class="text-lg font-bold mb-2" style="font-family: 'Syne', sans-serif; color: #f1f0ff;">No categories yet</h3>
            <p class="text-sm" style="color: #6b6b8a;">The forum is being set up. Check back soon!</p>
        </div>
        {% endif %}
    </div>
</section>

<!-- Recent Activity -->
<section class="py-16 relative">
    <div class="absolute inset-0 dot-grid opacity-20 pointer-events-none"></div>
    <div class="relative max-w-5xl mx-auto px-4 sm:px-6 lg:px-8">
        <div class="mb-6 text-xs font-semibold tracking-widest uppercase" style="color: #6b6b8a; font-family: 'Syne', sans-serif;">Recent Activity</div>

        {% if recent_topics %}
        <div class="space-y-3">
            {% for topic in recent_topics %}
            <div class="card flex items-center gap-4 p-5" style="border: 1px solid rgba(255,255,255,0.05);">
                <div class="avatar w-9 h-9 text-xs font-bold flex-shrink-0">{{ topic.author.username[0].upper() }}</div>
                <div class="flex-grow min-w-0">
                    <a href="{{ url_for('forum_topic', category_slug=topic.category.slug, topic_id=topic.id) }}"
                       class="text-sm font-semibold text-gray-200 hover:text-primary-300 transition-colors truncate block">
                        {{ topic.title }}
                    </a>
                    <div class="text-xs mt-0.5" style="color: #6b6b8a;">
                        by {{ topic.author.username }} in
                        <a href="{{ url_for('forum_category', slug=topic.category.slug) }}" class="text-primary-500 hover:text-primary-400">{{ topic.category.name }}</a>
                    </div>
                </div>
                <div class="flex-shrink-0 text-right">
                    <div class="text-xs font-semibold" style="color: #e8e6f0;">{{ topic.reply_count }}</div>
                    <div class="text-xs" style="color: #6b6b8a;">replies</div>
                </div>
            </div>
            {% endfor %}
        </div>
        {% else %}
        <p class="text-sm text-center py-10" style="color: #6b6b8a;">No recent activity yet.</p>
        {% endif %}
    </div>
</section>

{% endblock %}
