{% extends 'base.html' %}

{% block title %}通知公告 - 图书管理系统{% endblock %}

{% block head %}
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Poppins:wght@400;600;700&family=Nunito+Sans:wght@400;600&display=swap" rel="stylesheet">
<link rel="stylesheet" href="{{ url_for('static', filename='css/announcement-list.css') }}">
{% endblock %}

{% block content %}
<div class="announcement-container">
    <div class="page-header">
        <h1><i class="fas fa-bullhorn page-icon"></i> 通知公告</h1>
        {# Optional: Add a create button if applicable for admins #}
        {# <a href="{{ url_for('announcement.create_announcement') }}" class="btn btn-fresh-create">
            <i class="fas fa-plus"></i> 发布新公告
        </a> #}
    </div>

    <div class="announcement-list">
        {% if pagination.items %}
            {% for announcement in pagination.items %}
                <div class="announcement-item {% if announcement.is_top %}pinned{% endif %}">
                    {% if announcement.is_top %}
                    <div class="pin-badge">
                        <i class="fas fa-thumbtack"></i> 置顶推荐
                    </div>
                    {% endif %}
                    <div class="announcement-header">
                        <h3><a href="{{ url_for('announcement.announcement_detail', announcement_id=announcement.id) }}">{{ announcement.title }}</a></h3>
                        <span class="date">{{ announcement.created_at.strftime('%Y年%m月%d日') }}</span>
                    </div>
                    <div class="announcement-preview">
                        {{ announcement.content|striptags|truncate(130) }}
                    </div>
                    <div class="announcement-footer">
                        <span class="publisher">
                            <i class="fas fa-user-circle"></i>
                            发布者: {{ announcement.publisher.username if announcement.publisher else '系统管理员' }}
                        </span>
                        <a href="{{ url_for('announcement.announcement_detail', announcement_id=announcement.id) }}" class="read-more">
                            阅读全文 <i class="fas fa-arrow-right"></i>
                        </a>
                    </div>
                </div>
            {% endfor %}

            <!-- 分页 -->
            <div class="pagination-container">
                {% if pagination.pages > 1 %}
                <nav aria-label="Page navigation">
                    <ul class="pagination">
                        {% if pagination.has_prev %}
                        <li class="page-item">
                            <a class="page-link" href="{{ url_for('announcement.announcement_list', page=pagination.prev_num) }}" aria-label="Previous">
                                <span aria-hidden="true">&laquo;</span>
                            </a>
                        </li>
                        {% else %}
                        <li class="page-item disabled">
                            <a class="page-link" href="#" aria-label="Previous">
                                <span aria-hidden="true">&laquo;</span>
                            </a>
                        </li>
                        {% endif %}

                        {% for page_num in pagination.iter_pages(left_edge=1, right_edge=1, left_current=1, right_current=1) %}
                            {% if page_num %}
                                {% if page_num == pagination.page %}
                                <li class="page-item active">
                                    <a class="page-link" href="{{ url_for('announcement.announcement_list', page=page_num) }}">{{ page_num }}</a>
                                </li>
                                {% else %}
                                <li class="page-item">
                                    <a class="page-link" href="{{ url_for('announcement.announcement_list', page=page_num) }}">{{ page_num }}</a>
                                </li>
                                {% endif %}
                            {% else %}
                                <li class="page-item disabled">
                                    <a class="page-link" href="#">...</a>
                                </li>
                            {% endif %}
                        {% endfor %}

                        {% if pagination.has_next %}
                        <li class="page-item">
                            <a class="page-link" href="{{ url_for('announcement.announcement_list', page=pagination.next_num) }}" aria-label="Next">
                                <span aria-hidden="true">&raquo;</span>
                            </a>
                        </li>
                        {% else %}
                        <li class="page-item disabled">
                            <a class="page-link" href="#" aria-label="Next">
                                <span aria-hidden="true">&raquo;</span>
                            </a>
                        </li>
                        {% endif %}
                    </ul>
                </nav>
                {% endif %}
            </div>
        {% else %}
            <div class="no-records">
                 <img src="data:image/svg+xml;charset=UTF-8,%3csvg width='80' height='80' viewBox='0 0 24 24' fill='none' xmlns='http://www.w3.org/2000/svg'%3e%3cpath d='M12 2C6.48 2 2 6.48 2 12C2 17.52 6.48 22 12 22C17.52 22 22 17.52 22 12C22 6.48 17.52 2 12 2ZM13 17H11V15H13V17ZM13 13H11V7H13V13Z' fill='%23FFAAA5'/%3e%3c/svg%3e" alt="No announcements icon" class="no-records-icon">
                <p>暂时还没有新的通知公告哦，敬请期待！</p>
            </div>
        {% endif %}
    </div>
</div>
{% endblock %}

{% block scripts %}
{# <script src="{{ url_for('static', filename='js/announcement-list.js') }}"></script> #}
{# Assuming announcement-list.js is for interactivity not directly tied to styling #}
{% endblock %}
