{% extends "base.html" %}

{% block title %}Forum - Norda Biznes Hub{% endblock %}

{% block extra_css %}
<style>
    .forum-header {
        display: flex;
        justify-content: space-between;
        align-items: center;
        margin-bottom: var(--spacing-xl);
    }

    .forum-header h1 {
        font-size: var(--font-size-3xl);
        color: var(--text-primary);
    }

    .forum-stats {
        color: var(--text-secondary);
        font-size: var(--font-size-sm);
    }

    .topics-list {
        display: flex;
        flex-direction: column;
        gap: var(--spacing-md);
    }

    .topic-card {
        background: var(--surface);
        border-radius: var(--radius-lg);
        padding: var(--spacing-lg);
        box-shadow: var(--shadow);
        transition: var(--transition);
        display: grid;
        grid-template-columns: 1fr auto;
        gap: var(--spacing-lg);
        align-items: center;
    }

    .topic-card:hover {
        box-shadow: var(--shadow-md);
        transform: translateY(-2px);
    }

    .topic-card.pinned {
        border-left: 4px solid var(--primary);
        background: linear-gradient(135deg, #eff6ff, var(--surface));
    }

    .topic-card.locked {
        opacity: 0.7;
    }

    .topic-main {
        min-width: 0;
    }

    .topic-title {
        font-size: var(--font-size-lg);
        font-weight: 600;
        color: var(--text-primary);
        text-decoration: none;
        display: flex;
        align-items: center;
        gap: var(--spacing-sm);
    }

    .topic-title:hover {
        color: var(--primary);
    }

    .topic-badge {
        font-size: var(--font-size-sm);
        padding: 2px 8px;
        border-radius: var(--radius-sm);
        font-weight: 500;
    }

    .badge-pinned {
        background: var(--primary);
        color: white;
    }

    .badge-locked {
        background: var(--secondary);
        color: white;
    }

    .topic-meta {
        display: flex;
        gap: var(--spacing-lg);
        margin-top: var(--spacing-sm);
        font-size: var(--font-size-sm);
        color: var(--text-secondary);
    }

    .topic-meta span {
        display: flex;
        align-items: center;
        gap: var(--spacing-xs);
    }

    .topic-stats {
        display: flex;
        flex-direction: column;
        align-items: flex-end;
        gap: var(--spacing-xs);
        text-align: right;
    }

    .stat-item {
        display: flex;
        align-items: center;
        gap: var(--spacing-xs);
        font-size: var(--font-size-sm);
        color: var(--text-secondary);
    }

    .stat-item strong {
        color: var(--text-primary);
    }

    .empty-state {
        text-align: center;
        padding: var(--spacing-2xl);
        color: var(--text-secondary);
    }

    .empty-state h3 {
        margin-bottom: var(--spacing-md);
        color: var(--text-primary);
    }

    .pagination {
        display: flex;
        justify-content: center;
        gap: var(--spacing-sm);
        margin-top: var(--spacing-xl);
    }

    .pagination a, .pagination span {
        padding: var(--spacing-sm) var(--spacing-md);
        border-radius: var(--radius);
        text-decoration: none;
        font-weight: 500;
    }

    .pagination a {
        background: var(--surface);
        color: var(--text-primary);
        border: 1px solid var(--border);
    }

    .pagination a:hover {
        background: var(--background);
        border-color: var(--primary);
    }

    .pagination span.current {
        background: var(--primary);
        color: white;
    }

    @media (max-width: 768px) {
        .forum-header {
            flex-direction: column;
            align-items: flex-start;
            gap: var(--spacing-md);
        }

        .topic-card {
            grid-template-columns: 1fr;
        }

        .topic-stats {
            flex-direction: row;
            align-items: center;
        }
    }
</style>
{% endblock %}

{% block content %}
<div class="forum-header">
    <div>
        <h1>Forum Norda Biznes</h1>
        <p class="forum-stats">{{ total_topics }} tematow</p>
    </div>
    <a href="{{ url_for('forum_new_topic') }}" class="btn btn-primary">
        + Nowy temat
    </a>
</div>

{% if topics %}
<div class="topics-list">
    {% for topic in topics %}
    <article class="topic-card {% if topic.is_pinned %}pinned{% endif %} {% if topic.is_locked %}locked{% endif %}">
        <div class="topic-main">
            <a href="{{ url_for('forum_topic', topic_id=topic.id) }}" class="topic-title">
                {% if topic.is_pinned %}
                <span class="topic-badge badge-pinned">Przypiety</span>
                {% endif %}
                {% if topic.is_locked %}
                <span class="topic-badge badge-locked">Zamkniety</span>
                {% endif %}
                {{ topic.title }}
            </a>
            <div class="topic-meta">
                <span>
                    <svg width="16" height="16" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24">
                        <path d="M20 21v-2a4 4 0 0 0-4-4H8a4 4 0 0 0-4 4v2"></path>
                        <circle cx="12" cy="7" r="4"></circle>
                    </svg>
                    {{ topic.author.name or topic.author.email.split('@')[0] }}
                </span>
                <span>
                    <svg width="16" height="16" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24">
                        <circle cx="12" cy="12" r="10"></circle>
                        <polyline points="12 6 12 12 16 14"></polyline>
                    </svg>
                    {{ topic.created_at.strftime('%d.%m.%Y %H:%M') }}
                </span>
            </div>
        </div>
        <div class="topic-stats">
            <div class="stat-item">
                <svg width="16" height="16" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24">
                    <path d="M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"></path>
                </svg>
                <strong>{{ topic.reply_count }}</strong> odpowiedzi
            </div>
            <div class="stat-item">
                <svg width="16" height="16" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24">
                    <path d="M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z"></path>
                    <circle cx="12" cy="12" r="3"></circle>
                </svg>
                <strong>{{ topic.views_count }}</strong> wyswietlen
            </div>
        </div>
    </article>
    {% endfor %}
</div>

{% if total_pages > 1 %}
<nav class="pagination">
    {% if page > 1 %}
    <a href="{{ url_for('forum_index', page=page-1) }}">&laquo; Poprzednia</a>
    {% endif %}

    {% for p in range(1, total_pages + 1) %}
        {% if p == page %}
        <span class="current">{{ p }}</span>
        {% elif p <= 3 or p > total_pages - 3 or (p >= page - 1 and p <= page + 1) %}
        <a href="{{ url_for('forum_index', page=p) }}">{{ p }}</a>
        {% elif p == 4 or p == total_pages - 3 %}
        <span>...</span>
        {% endif %}
    {% endfor %}

    {% if page < total_pages %}
    <a href="{{ url_for('forum_index', page=page+1) }}">Nastepna &raquo;</a>
    {% endif %}
</nav>
{% endif %}

{% else %}
<div class="empty-state">
    <svg width="64" height="64" fill="none" stroke="currentColor" stroke-width="1.5" viewBox="0 0 24 24" style="margin: 0 auto var(--spacing-md); display: block; opacity: 0.5;">
        <path d="M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"></path>
    </svg>
    <h3>Brak tematow</h3>
    <p>Badz pierwszy! Utworz nowy temat dyskusji.</p>
    <a href="{{ url_for('forum_new_topic') }}" class="btn btn-primary mt-2">
        + Utworz pierwszy temat
    </a>
</div>
{% endif %}
{% endblock %}
