{% extends 'base.html' %}
{% load static %}

{% block title %}Home - Packs Site{% endblock %}

{% block content %}
<div class="home-layout">
    <div class="home-hero">
        <div class="home-hero-inner">
            <h1>Packs Site</h1>
            <p>Hosted datapacks for the Needs Of Nature mod.</p>
            <p class="home-hero-sub">Browse and download packs shared by the community. Upload your own once you have a creator account.</p>
            <div class="home-hero-actions">
                <a href="{% url 'library:browse' %}" class="btn btn-primary"><i class="fas fa-search"></i> Browse packs</a>
                <a href="{% url 'library:my_projects' %}" class="btn btn-secondary"><i class="fas fa-folder-open"></i> My Projects</a>
            </div>
        </div>
    </div>

    <div class="home-placeholder">
        <h2><i class="fas fa-bullhorn"></i> Announcements</h2>
        <div class="announce-panel">
            {% for a in announcements %}
                <div class="announce-item{% if a.pk not in global_read_ids and user.is_authenticated %} announce-unread{% endif %}">
                    <a href="{% url 'announcements:detail' a.pk %}">{{ a.title }}</a>
                    <span class="announce-meta">{{ a.created_at|date:"M j" }}{% if a.comments_count %} · {{ a.comments_count }} comment{{ a.comments_count|pluralize }}{% endif %}</span>
                </div>
            {% empty %}
                <p class="empty-hint">No announcements yet.</p>
            {% endfor %}
        </div>
        {% if announcements_total > 4 %}
            <a href="{% url 'announcements:list' %}" class="announce-more">View all ({{ announcements_total }}) <i class="fas fa-arrow-right"></i></a>
        {% endif %}

        {% if user.is_authenticated %}
            <h2 class="announce-subhead"><i class="fas fa-bell"></i> For you
                {% if unread_notifications %}<span class="announce-badge">{{ unread_notifications }}</span>{% endif %}
            </h2>
            <div class="announce-panel">
                {% for n in notifications %}
                    <div class="announce-item{% if not n.read %} announce-unread{% endif %}">
                        <a href="{% url 'library:project_detail' n.project.slug %}">{{ n.text }}</a>
                        <span class="announce-meta">{{ n.created_at|timesince }} ago</span>
                    </div>
                {% empty %}
                    <p class="empty-hint">Nothing new for you yet.</p>
                {% endfor %}
            </div>
            <div class="announce-actions">
                <a href="{% url 'announcements:personal' %}" class="announce-more">All your alerts <i class="fas fa-arrow-right"></i></a>
                {% if unread_notifications %}
                    <form method="post" action="{% url 'announcements:mark_all_read' %}">
                        {% csrf_token %}
                        <button type="submit" class="link-btn">Mark all read</button>
                    </form>
                {% endif %}
            </div>
        {% endif %}
    </div>

    <div class="home-stats">
        <div class="stat-card">
            <i class="fas fa-users"></i>
            <span class="stat-value">{{ stats.creators }}</span>
            <span class="stat-label">Creators</span>
        </div>
        <div class="stat-card">
            <i class="fas fa-box-open"></i>
            <span class="stat-value">{{ stats.packs }}</span>
            <span class="stat-label">Packs</span>
        </div>
        <div class="stat-card">
            <i class="fas fa-download"></i>
            <span class="stat-value">{{ stats.downloads }}</span>
            <span class="stat-label">Downloads</span>
        </div>
    </div>
</div>

{% for row in home_rows %}
<div class="home-cat-row">
    {% for section in row %}
    <div class="home-cat-block">
        <div class="home-section-header">
            <h2>{{ section.label }}</h2>
            <a href="{% url 'library:browse' %}?category={{ section.value }}" class="home-section-link">View all <i class="fas fa-arrow-right"></i></a>
        </div>
        <div class="home-cat-cols">
            <div class="home-cat-col">
                <h3 class="home-cat-head"><i class="fas fa-fire"></i> Popular</h3>
                <div class="pack-row-list">
                    {% for project in section.popular %}
                        {% include 'library/_project_card_row.html' %}
                    {% empty %}
                        <p class="empty-hint">None yet.</p>
                    {% endfor %}
                </div>
            </div>
            <div class="home-cat-divider" role="separator"></div>
            <div class="home-cat-col">
                <h3 class="home-cat-head"><i class="fas fa-clock"></i> Recent</h3>
                <div class="pack-row-list">
                    {% for project in section.recent %}
                        {% include 'library/_project_card_row.html' %}
                    {% empty %}
                        <p class="empty-hint">None yet.</p>
                    {% endfor %}
                </div>
            </div>
        </div>
    </div>
    {% if not forloop.last %}<div class="home-cat-row-divider" role="separator"></div>{% endif %}
    {% endfor %}
</div>
{% endfor %}
{% endblock %}
