{% extends "base.html" %}
{% block title %}RSS Reader{% endblock %}
{% block content %}
<div class="bbs-header">
    <h1><i class="bi bi-rss-fill"></i> RSS Reader</h1>
    <p>
        {% if total_unread %}
            <strong>{{ total_unread }}</strong> unread item{{ '' if total_unread == 1 else 's' }} across {{ feeds|length }} feed{{ '' if feeds|length == 1 else 's' }}.
        {% else %}
            All caught up — {{ feeds|length }} feed{{ '' if feeds|length == 1 else 's' }} subscribed.
        {% endif %}
    </p>
</div>

<div class="d-flex gap-2 mb-3">
    <a href="{{ url_for('rss.river') }}" class="btn btn-primary">
        <i class="bi bi-water"></i> All Feeds (River)
    </a>
    {% if current_user.is_admin %}
    <a href="{{ url_for('rss_admin.index') }}" class="btn btn-secondary">
        <i class="bi bi-gear"></i> Manage Feeds
    </a>
    {% endif %}
    {% if total_unread %}
    <form method="post" action="{{ url_for('rss.mark_all_read') }}" class="d-inline">
        <input type="hidden" name="csrf_token" value="{{ csrf_token() }}">
        <button class="btn btn-outline-secondary">
            <i class="bi bi-check2-all"></i> Mark all read
        </button>
    </form>
    {% endif %}
</div>

{% if feeds %}
<div class="list-group">
    {% for feed in feeds %}
    <a href="{{ url_for('rss.view_feed', feed_id=feed.id) }}"
       class="list-group-item list-group-item-action d-flex justify-content-between align-items-start">
        <div>
            <h5 class="mb-1">
                <i class="bi bi-rss"></i> {{ feed.name }}
                {% if feed_unread.get(feed.id, 0) %}
                <span class="badge bg-primary">{{ feed_unread[feed.id] }} new</span>
                {% endif %}
            </h5>
            {% if feed.description %}
            <p class="mb-1 small text-muted">{{ feed.description }}</p>
            {% endif %}
            <small class="text-muted">
                <code>{{ feed.url }}</code>
                {% if feed.last_fetched_at %}
                · last fetched {{ feed.last_fetched_at.strftime('%Y-%m-%d %H:%M UTC') }}
                {% endif %}
                {% if feed.last_error %}
                · <span class="text-danger" title="{{ feed.last_error }}">⚠ error</span>
                {% endif %}
            </small>
        </div>
        <span class="badge bg-secondary rounded-pill align-self-center">
            {{ feed.items|length }} total
        </span>
    </a>
    {% endfor %}
</div>
{% else %}
<div class="alert alert-info">
    <i class="bi bi-info-circle"></i> No RSS feeds configured yet.
    {% if current_user.is_admin %}
    <a href="{{ url_for('rss_admin.add') }}">Add one →</a>
    {% else %}
    Ask the sysop to add one.
    {% endif %}
</div>
{% endif %}
{% endblock %}
