<%@ page contentType="text/html;charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!doctype html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>报表 - MZH 图书馆</title>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/static/css/app.css?v=20260428-visual-shell">
</head>
<body>
<%@ include file="/WEB-INF/jsp/common/header.jspf" %>
<main class="page-shell">
    <section class="dashboard-hero catalog-hero" aria-labelledby="reports-title">
        <div>
            <p class="eyebrow">报表</p>
            <h1 id="reports-title">报表中心</h1>
            <p>查看馆藏库存、借阅状况、逾期借阅和热门图书。</p>
        </div>
    </section>

    <c:if test="${not empty errorMessage}">
        <div class="message message-error" role="alert">
            <c:out value="${errorMessage}" />
        </div>
    </c:if>

    <c:if test="${not empty reportCenter}">
        <section class="report-grid" aria-label="报表摘要">
            <article class="report-card">
                <p class="eyebrow">库存</p>
                <h2>图书种类总数</h2>
                <p class="report-metric"><c:out value="${reportCenter.inventorySummary.totalTitles}" /></p>
            </article>
            <article class="report-card">
                <p class="eyebrow">库存</p>
                <h2>馆藏总册数</h2>
                <p class="report-metric"><c:out value="${reportCenter.inventorySummary.totalCopies}" /></p>
            </article>
            <article class="report-card">
                <p class="eyebrow">库存</p>
                <h2>可借册数</h2>
                <p class="report-metric"><c:out value="${reportCenter.inventorySummary.availableCopies}" /></p>
            </article>
            <article class="report-card">
                <p class="eyebrow">需关注</p>
                <h2>不可借或无库存</h2>
                <p class="report-metric"><c:out value="${reportCenter.inventorySummary.unavailableOrEmptyTitles}" /></p>
            </article>
            <article class="report-card">
                <p class="eyebrow">借阅</p>
                <h2>当前借出</h2>
                <p class="report-metric"><c:out value="${reportCenter.borrowingSummary.activeLoans}" /></p>
            </article>
            <article class="report-card">
                <p class="eyebrow">借阅</p>
                <h2>已归还记录</h2>
                <p class="report-metric"><c:out value="${reportCenter.borrowingSummary.returnedLoans}" /></p>
            </article>
            <article class="report-card report-card-alert">
                <p class="eyebrow">借阅</p>
                <h2>逾期借阅</h2>
                <p class="report-metric"><c:out value="${reportCenter.borrowingSummary.overdueLoans}" /></p>
            </article>
        </section>

        <section class="table-panel" aria-labelledby="overdue-report-title">
            <h2 id="overdue-report-title">逾期列表</h2>
            <c:choose>
                <c:when test="${empty reportCenter.overdueRows}">
                    <p class="empty-state">当前没有逾期未还的借阅记录。</p>
                </c:when>
                <c:otherwise>
                    <div class="table-scroll">
                        <table class="data-table">
                            <thead>
                            <tr>
                                <th scope="col">读者</th>
                                <th scope="col">图书</th>
                                <th scope="col">应还日期</th>
                                <th scope="col">逾期天数</th>
                            </tr>
                            </thead>
                            <tbody>
                            <c:forEach var="row" items="${reportCenter.overdueRows}">
                                <tr>
                                    <td>
                                        <strong><c:out value="${row.readerIdentifier}" /></strong>
                                        <div class="muted-text"><c:out value="${row.readerName}" /></div>
                                    </td>
                                    <td>
                                        <strong><c:out value="${row.bookIdentifier}" /></strong>
                                        <div class="muted-text"><c:out value="${row.bookTitle}" /></div>
                                    </td>
                                    <td><c:out value="${row.dueAtText}" /></td>
                                    <td>
                                        <span class="status-pill status-overdue">
                                            <c:out value="${row.overdueDays}" /> 天
                                        </span>
                                    </td>
                                </tr>
                            </c:forEach>
                            </tbody>
                        </table>
                    </div>
                </c:otherwise>
            </c:choose>
        </section>

        <section class="table-panel" aria-labelledby="popular-report-title">
            <h2 id="popular-report-title">热门借阅排行</h2>
            <c:choose>
                <c:when test="${empty reportCenter.popularBooks}">
                    <p class="empty-state">暂无可用于排行的借阅记录。</p>
                </c:when>
                <c:otherwise>
                    <div class="table-scroll">
                        <table class="data-table">
                            <thead>
                            <tr>
                                <th scope="col">图书</th>
                                <th scope="col">作者</th>
                                <th scope="col">借阅次数</th>
                            </tr>
                            </thead>
                            <tbody>
                            <c:forEach var="row" items="${reportCenter.popularBooks}">
                                <tr>
                                    <td>
                                        <strong><c:out value="${row.bookIdentifier}" /></strong>
                                        <div class="muted-text"><c:out value="${row.title}" /></div>
                                    </td>
                                    <td><c:out value="${row.author}" /></td>
                                    <td><c:out value="${row.borrowCount}" /></td>
                                </tr>
                            </c:forEach>
                            </tbody>
                        </table>
                    </div>
                </c:otherwise>
            </c:choose>
        </section>
    </c:if>
</main>
</body>
</html>
