<!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/police/personnelStatus.js}"></script>
</th:block>
<div layout:fragment="content">
  <main class="pt-3">
    <h4>외사경찰 정원/현원 현황</h4>
    <input type="hidden" name="_csrf_header" th:value="${_csrf.headerName}"/>
    <input type="hidden" th:name="${_csrf.parameterName}" th:value="${_csrf.token}"/>
    <div class="row mx-0">
      <div class="col-12 card text-center">
        <div class="card-body">
          <form id="searchFm" method="get" th:action="@{/police/personnelStatus}">
            <div class="row justify-content-between py-1">
              <div class="col-auto">
                <select class="form-select" name="year" id="year">
                  <th:block th:each="year : ${#numbers.sequence(2020, 2040)}">
                    <option th:value="${year}" th:text="${year}" th:selected="${#strings.toString(year) eq searchParams.year}"></option>
                  </th:block>
                </select>
              </div>
              <div class="col-auto">
                <button type="button" class="btn btn-sm btn-primary" id="personnelStatusEditModalBtn" th:if="${accessAuth ne 'ACC001'}">등록</button>
                <button type="button" class="btn btn-sm btn-success" id="personnelStatusExcelBtn">엑셀 다운로드</button>
              </div>
            </div>
          </form>
          <div class="row justify-content-start">
            <div class="col-12">
              <div class="card">
                <div class="card-body">
                  <table class="table table-hover table-bordered" id="psTable">
                    <thead>
                    <tr class="table-secondary">
                      <th rowspan="3">관서</th>
                      <th>정원</th>
                      <th>현원</th>
                      <th>과부족</th>
                      <th:block th:each="code:${jtList}">
                        <th colspan="2" th:text="${code.itemValue}"></th>
                      </th:block>
                      <th rowspan="3">수정일</th>
                    </tr>
                    <tr class="table-secondary">
                      <th>계</th>
                      <th>계</th>
                      <th>계</th>
                      <th:block th:each="code:${jtList}">
                        <th>정원</th>
                        <th>현원</th>
                      </th:block>
                    </tr>
                    <tr class="table-secondary">
                      <th th:text="${statusSummary.sumMax}"></th>
                      <th th:text="${statusSummary.sumNow}"></th>
                      <th th:text="${statusSummary.sumNow-statusSummary.sumMax}" th:classappend="${(statusSummary.sumNow-statusSummary.sumMax)>=0?'text-primary':'text-danger'}"></th>
                      <th th:text="${statusSummary.jt007Max}"></th>
                      <th th:text="${statusSummary.jt007Now}"></th>
                      <th th:text="${statusSummary.jt006Max}"></th>
                      <th th:text="${statusSummary.jt006Now}"></th>
                      <th th:text="${statusSummary.jt005Max}"></th>
                      <th th:text="${statusSummary.jt005Now}"></th>
                      <th th:text="${statusSummary.jt004Max}"></th>
                      <th th:text="${statusSummary.jt004Now}"></th>
                      <th th:text="${statusSummary.jt003Max}"></th>
                      <th th:text="${statusSummary.jt003Now}"></th>
                      <th th:text="${statusSummary.jt002Max}"></th>
                      <th th:text="${statusSummary.jt002Now}"></th>
                      <th th:text="${statusSummary.jt001Max}"></th>
                      <th th:text="${statusSummary.jt001Now}"></th>
                    </tr>
                    </thead>
                    <tbody class="table-group-divider">
                    <tr class="statusTr" th:each="status:${statusList}" th:data-year="${status.year}" th:data-ogcd="${status.ogCd}">
                      <th:block th:each="code:${session.commonCode.get('OG')}">
                        <th:block th:if="${code.itemCd eq status.ogCd}">
                          <td th:text="${code.itemValue}"></td>
                        </th:block>
                      </th:block>
                      <td th:text="${status.sumMax}"></td>
                      <td th:text="${status.sumNow}"></td>
                      <td th:text="${status.sumNow-status.sumMax}" th:classappend="${(status.sumNow-status.sumMax)>=0?'text-primary':'text-danger'}"></td>
                      <td th:text="${status.jt007Max}"></td>
                      <td th:text="${status.jt007Now}"></td>
                      <td th:text="${status.jt006Max}"></td>
                      <td th:text="${status.jt006Now}"></td>
                      <td th:text="${status.jt005Max}"></td>
                      <td th:text="${status.jt005Now}"></td>
                      <td th:text="${status.jt004Max}"></td>
                      <td th:text="${status.jt004Now}"></td>
                      <td th:text="${status.jt003Max}"></td>
                      <td th:text="${status.jt003Now}"></td>
                      <td th:text="${status.jt002Max}"></td>
                      <td th:text="${status.jt002Now}"></td>
                      <td th:text="${status.jt001Max}"></td>
                      <td th:text="${status.jt001Now}"></td>
                      <td th:text="${#temporals.format(status.wrtDt, 'yyyy-MM-dd HH:mm')}"></td>
                    </tr>
                    </tbody>
                  </table>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </main>

  <div class="modal fade" id="personnelStatusEditModal" data-bs-backdrop="static" data-bs-keyboard="false" tabindex="-1" aria-labelledby="personnelStatusEditModalLabel" aria-hidden="true">
    <div class="modal-dialog modal-xxl modal-dialog-scrollable">
      <div class="modal-content" id="personnelStatusEditModalContent">
        <div class="modal-header">
          <h5 class="modal-title" id="personnelStatusEditModalLabel">정원/현원 현황 등록</h5>
          <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
        </div>
        <div class="modal-body">
          <div class="row">
            <div class="col-12">
              <div class="card">
                <div class="card-body">
                  <div class="row text-center justify-content-around">
                    <div class="col-1">관서</div>
                    <th:block th:each="code:${jtList}">
                      <div class="col-1">
                        <div class="row">
                          <div class="col-12 px-0" th:text="${code.itemValue}"></div>
                          <div class="col-6 px-0">정원</div>
                          <div class="col-6 px-0">현원</div>
                        </div>
                      </div>
                    </th:block>
                    <div class="col-2"></div>
                  </div>
                  <div class="row" id="personnelStatusEditDiv">

                  </div>
                  <div class="row justify-content-center pt-3">
                    <div class="col-auto">
                      <button type="button" class="btn btn-sm btn-primary" id="personnelStatusAddBtn">추가</button>
                    </div>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>
        <div class="modal-footer">
          <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">닫기</button>
          <button type="button" class="btn btn-primary" id="saveBtn">저장</button>
        </div>
      </div>
    </div>
  </div>

  <div class="modal fade" id="personnelStatusHistoryModal" data-bs-backdrop="static" data-bs-keyboard="false" tabindex="-1" aria-labelledby="personnelStatusHistoryModalLabel" aria-hidden="true">
    <div class="modal-dialog modal-xxl modal-dialog-scrollable">
      <div class="modal-content">
        <div class="modal-header">
          <h5 class="modal-title" id="personnelStatusHistoryModalLabel">수정이력조회</h5>
          <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
        </div>
        <div class="modal-body" id="personnelStatusHistoryModalBody">

        </div>
        <div class="modal-footer">
          <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">닫기</button>
        </div>
      </div>
    </div>
  </div>

</div>
</html>