<%@ 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="category-title">
        <div>
            <p class="eyebrow">图书管理</p>
            <h1 id="category-title">管理分类</h1>
            <p>维护图书记录和检索筛选使用的馆藏分组。</p>
        </div>
        <div class="hero-actions">
            <a class="button button-primary" href="${pageContext.request.contextPath}/book-categories/new">新增分类</a>
        </div>
    </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="category-results-title">
        <h2 id="category-results-title">分类记录</h2>
        <c:choose>
            <c:when test="${empty categories}">
                <p class="empty-state">尚未创建分类。</p>
            </c:when>
            <c:otherwise>
                <div class="table-scroll">
                    <table class="data-table category-table">
                        <thead>
                        <tr>
                            <th scope="col">名称</th>
                            <th scope="col">说明</th>
                            <th scope="col">操作</th>
                        </tr>
                        </thead>
                        <tbody>
                        <c:forEach var="category" items="${categories}">
                            <tr>
                                <td><c:out value="${category.name}" /></td>
                                <td>
                                    <c:choose>
                                        <c:when test="${empty category.description}">
                                            <span class="muted-text">无说明</span>
                                        </c:when>
                                        <c:otherwise>
                                            <c:out value="${category.description}" />
                                        </c:otherwise>
                                    </c:choose>
                                </td>
                                <td>
                                    <div class="table-actions">
                                        <a class="button button-secondary"
                                           href="${pageContext.request.contextPath}/book-categories/edit?id=${category.id}">编辑</a>
                                        <form action="${pageContext.request.contextPath}/book-categories/delete"
                                              method="post"
                                              onsubmit="return confirm('确定删除这个分类吗？');">
                                            <input type="hidden" name="id" value="${category.id}">
                                            <button class="button button-danger" type="submit">删除</button>
                                        </form>
                                    </div>
                                </td>
                            </tr>
                        </c:forEach>
                        </tbody>
                    </table>
                </div>
            </c:otherwise>
        </c:choose>
    </section>
</main>
</body>
</html>
