<%@ page contentType="text/html;charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<!doctype html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title><c:out value="${formTitle}" /> - 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="form-panel" aria-labelledby="category-form-title">
        <p class="eyebrow">图书管理</p>
        <h1 id="category-form-title"><c:out value="${formTitle}" /></h1>

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

        <c:set var="hasFormValues" value="${not empty formValues}" />
        <c:set var="nameValue" value="${hasFormValues ? formValues.name : category.name}" />
        <c:set var="descriptionValue" value="${hasFormValues ? formValues.description : category.description}" />

        <form class="category-form" action="${pageContext.request.contextPath}${formAction}" method="post" novalidate>
            <c:if test="${category.id > 0}">
                <input type="hidden" name="id" value="${category.id}">
            </c:if>

            <div class="form-grid">
                <div class="form-field">
                    <label for="name">分类名称</label>
                    <input id="name" name="name" type="text" value="${fn:escapeXml(nameValue)}" required>
                    <c:if test="${not empty errors.name}">
                        <span class="field-error"><c:out value="${errors.name}" /></span>
                    </c:if>
                </div>

                <div class="form-field form-field-wide">
                    <label for="description">说明</label>
                    <textarea id="description" name="description" rows="4">${fn:escapeXml(descriptionValue)}</textarea>
                    <c:if test="${not empty errors.description}">
                        <span class="field-error"><c:out value="${errors.description}" /></span>
                    </c:if>
                </div>
            </div>

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

            <div class="form-actions">
                <button class="button button-primary" type="submit">保存</button>
                <a class="button button-secondary" href="${pageContext.request.contextPath}/book-categories">取消</a>
            </div>
        </form>
    </section>
</main>
</body>
</html>
