<!DOCTYPE html>
<html lang="ko" xmlns:th="http://www.thymeleaf.org"
      xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
      layout:decorate="~{layout/layout}">
<th:block layout:fragment="script">
  <script type="text/javascript" th:src="@{/js/admin/categoryMgt.js}"></script>
</th:block>
<div layout:fragment="content">
  <main class="pt-3">
    <input type="hidden" name="_csrf_header" th:value="${_csrf.headerName}"/>
    <input type="hidden" th:name="${_csrf.parameterName}" th:value="${_csrf.token}"/>
    <h4>게시판 분류 관리</h4>
    <div class="row mx-0">
      <div class="col-auto card text-center">
        <div class="card-body">
          <div class="row justify-content-end">
            <input type="button" class="col-auto btn btn-primary mx-3" id="saveCategoryBtn" value="저장">
          </div>
          <div class="row justify-content-start">
            <div class="col-auto m-3 p-3 border">
              <div class="row-cols-6" id="depth1Div">
                <table class="table table-striped">
                  <thead data-depth="1">
                  <tr>
                    <th></th>
                    <th>대분류</th>
                  </tr>
                  </thead>
                  <tbody id="depth1Category">
                  <tr class="categoryTr" th:each="boardCategory:${categoryList}">
                    <td>
                      <input type="hidden" class="categorySeq" th:value="${boardCategory.categorySeq}">
                      <input type="checkbox" class="trCheckBox" th:value="${boardCategory.depth}">
                    </td>
                    <td>
                      <input type="hidden" class="depth" th:value="${boardCategory.depth}">
                      <input type="hidden" class="parentSeq" th:value="${boardCategory.parentSeq}">
                      <input type="text" class="form-control categoryName border-0 text-center bg-transparent" th:value="${boardCategory.categoryName}" readonly>
                    </td>
                  </tr>
                  </tbody>
                </table>
              </div>
              <div class="row justify-content-end">
                <div class="col-auto">
                  <input type="button" class="btn btn-success addCategoryBtn" value="추가" data-depth="1">
                </div>
                <div class="col-auto">
                  <input type="button" class="btn btn-danger deleteCategoryBtn" value="삭제" data-depth="1">
                </div>
              </div>
            </div>
            <div class="col-auto m-3 p-3 border">
              <div class="row-cols-6" id="depth2Div">
                <table class="table table-striped">
                  <thead>
                  <tr>
                    <th></th>
                    <th>연도</th>
                  </tr>
                  </thead>
                  <tbody id="depth2Category">
                  </tbody>
                </table>
              </div>
              <div class="row justify-content-end">
                <div class="col-auto">
                  <input type="button" class="btn btn-success addCategoryBtn" value="추가" data-depth="2">
                </div>
                <div class="col-auto">
                  <input type="button" class="btn btn-danger deleteCategoryBtn" value="삭제" data-depth="2">
                </div>
              </div>
            </div>
            <div class="col-auto m-3 p-3 border">
              <div class="row-cols-6" id="depth3Div">
                <table class="table table-striped">
                  <thead>
                  <tr>
                    <th></th>
                    <th>중분류</th>
                  </tr>
                  </thead>
                  <tbody id="depth3Category">
                  </tbody>
                </table>
              </div>
              <div class="row justify-content-end">
                <div class="col-auto">
                  <input type="button" class="btn btn-success addCategoryBtn" value="추가" data-depth="3">
                </div>
                <div class="col-auto">
                  <input type="button" class="btn btn-danger deleteCategoryBtn" value="삭제" data-depth="3">
                </div>
              </div>
            </div>
            <div class="col-auto m-3 p-3 border">
              <div class="row-cols-6" id="depth4Div">
                <table class="table table-striped">
                  <thead>
                  <tr>
                    <th></th>
                    <th>소분류</th>
                  </tr>
                  </thead>
                  <tbody id="depth4Category">
                  </tbody>
                </table>
              </div>
              <div class="row justify-content-end">
                <div class="col-auto">
                  <input type="button" class="btn btn-success addCategoryBtn" value="추가" data-depth="4">
                </div>
                <div class="col-auto">
                  <input type="button" class="btn btn-danger deleteCategoryBtn" value="삭제" data-depth="4">
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </main>
  <div style="display: none;">
    <table>
      <tbody id="appendTr">
      <tr>
        <td>
          <input type="hidden" class="categorySeq">
          <input type="checkbox" class="trCheckBox">
        </td>
        <td>
          <input type="hidden" class="parentSeq">
          <input type="hidden" class="depth">
          <input type="text" class="form-control categoryName">
        </td>
      </tr>
      </tbody>
    </table>
  </div>
</div>
</html>