<%@ 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="loan-history-title">
        <div>
            <p class="eyebrow">读者中心</p>
            <h1 id="loan-history-title">借阅历史</h1>
            <p>查看您的在借、已还和逾期借阅记录。</p>
        </div>
        <a class="button button-secondary" href="${pageContext.request.contextPath}/catalog">检索馆藏</a>
    </section>

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

    <section class="table-panel" aria-labelledby="loan-results-title">
        <h2 id="loan-results-title">借阅记录</h2>
        <c:choose>
            <c:when test="${empty borrowRecords}">
                <p class="empty-state">此账户暂无借阅记录。</p>
            </c:when>
            <c:otherwise>
                <div class="table-scroll">
                    <table class="data-table borrowing-table">
                        <thead>
                        <tr>
                            <th scope="col">图书编号</th>
                            <th scope="col">书名</th>
                            <th scope="col">借出时间</th>
                            <th scope="col">应还时间</th>
                            <th scope="col">归还时间</th>
                            <th scope="col">续借次数</th>
                            <th scope="col">状态</th>
                        </tr>
                        </thead>
                        <tbody>
                        <c:forEach var="record" items="${borrowRecords}">
                            <tr>
                                <td><c:out value="${record.bookIdentifier}" /></td>
                                <td><c:out value="${record.bookTitle}" /></td>
                                <td><c:out value="${record.borrowedAtText}" /></td>
                                <td><c:out value="${record.dueAtText}" /></td>
                                <td>
                                    <c:choose>
                                        <c:when test="${not empty record.returnedAtText}">
                                            <c:out value="${record.returnedAtText}" />
                                        </c:when>
                                        <c:otherwise>未归还</c:otherwise>
                                    </c:choose>
                                </td>
                                <td><c:out value="${record.renewalCount}" /></td>
                                <td>
                                    <span class="status-pill status-${record.displayStatusCode}">
                                        <c:out value="${record.displayStatusName}" />
                                    </span>
                                </td>
                            </tr>
                        </c:forEach>
                        </tbody>
                    </table>
                </div>
            </c:otherwise>
        </c:choose>
    </section>
</main>
</body>
</html>
