<!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/userMgt/userMgt.js}"></script>
</th:block>
<div layout:fragment="content">
  <main class="pt-3">
    <h4>외사경찰 관리</h4>
    <ul class="nav nav-tabs" id="boardTab" role="tablist">
      <li class="nav-item" role="presentation">
        <button class="nav-link" th:classappend="${searchParams.userStatus eq 'USC003'?'active':''}" id="apprvTab" data-bs-toggle="tab" type="button" role="tab">승인목록</button>
      </li>
      <li class="nav-item" role="presentation">
        <button class="nav-link" th:classappend="${searchParams.userStatus ne 'USC003'?'active':''}" id="stayTab" data-bs-toggle="tab" type="button" role="tab">승인대기</button>
      </li>
    </ul>
    <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 tab-content border border-top-0 p-2">
        <form method="get" th:action="@{/userMgt/userMgtPage}">
          <input type="hidden" name="userStatus" id="userStatus" th:value="${searchParams.userStatus}">
          <input type="hidden" name="pageIndex" id="pageIndex" th:value="${searchParams.pageIndex}">
          <div class="row justify-content-between pe-3 py-1">
            <div class="col-auto">
              <select class="form-select form-select-sm" name="rowCnt" id="rowCnt">
                <th:block th:each="num : ${#numbers.sequence(1,5)}">
                  <option th:value="${num*10}" th:text="${num*10}" th:selected="${searchParams.rowCnt==num*10}"></option>
                </th:block>
              </select>
            </div>
            <div class="col-auto">
              <div class="row justify-content-end">
                <div class="col-auto">
                  <select class="form-select form-select-sm" name="ogCd">
                    <option value="">관서 선택</option>
                    <th:block th:each="commonCode:${session.commonCode.get('OG')}">
                      <option th:value="${commonCode.itemCd}" th:text="${commonCode.itemValue}" th:selected="${searchParams.ogCd==commonCode.itemCd}"></option>
                    </th:block>
                  </select>
                </div>
                <div class="col-auto">
                  <select class="form-select form-select-sm" name="ofcCd">
                    <option value="">부서 선택</option>
                    <th:block th:each="commonCode:${session.commonCode.get('OFC')}">
                      <option th:value="${commonCode.itemCd}" th:text="${commonCode.itemValue}" th:selected="${searchParams.ofcCd==commonCode.itemCd}"></option>
                    </th:block>
                  </select>
                </div>
                <div class="col-auto">
                  <select class="form-select form-select-sm" name="titleCd">
                    <option value="">계급 선택</option>
                    <th:block th:each="commonCode:${session.commonCode.get('JT')}">
                      <option th:value="${commonCode.itemCd}" th:text="${commonCode.itemValue}" th:selected="${searchParams.titleCd==commonCode.itemCd}"></option>
                    </th:block>
                  </select>
                </div>
                <div class="col-auto">
                  <input type="text" class="form-control form-control-sm" name="userNm" placeholder="사용자명" th:value="${searchParams.userNm}">
                </div>
                <div class="col-auto">
                  <input type="text" class="form-control form-control-sm" name="userId" placeholder="사용자 아이디" th:value="${searchParams.userId}">
                </div>
                <input type="submit" class="btn btn-sm btn-primary col-auto" id="searchBtn" value="검색">
              </div>
            </div>
          </div>
        </form>
        <div class="row justify-content-start">
          <div class="col-12">
            <div class="card">
              <div class="card-body">
                <div class="row">
                  <table class="table table-striped">
                    <thead>
                    <tr class="table-secondary">
                      <th> <input type="checkbox" class="allChk"></th>
                      <th>소속</th>
                      <th>부서</th>
                      <th>계급</th>
                      <th>성명</th>
                      <th>아이디</th>
                      <th>식별번호</th>
                      <th>등록일</th>
                    </tr>
                    </thead>
                    <tbody>
                    <tr class="userInfoTr" th:each="userInfo:${userInfoList}">
                      <input type="hidden" name="userSeq" class="userSeq" th:value="${userInfo.userSeq}">
                      <input type="hidden" name="dicCode" class="dicCode" th:value="${userInfo.dicCode}">
                      <td class="checkBoxTd">
                        <input type="checkbox" id="userChk" name="userChk" class="userInfoCheckBox" th:value="${userInfo.userSeq}">
                      </td>
                      <th:block th:if="${userInfo.ogCd eq null or userInfo.ogCd eq ''}">
                        <td></td>
                      </th:block>
                      <th:block th:unless="${userInfo.ogCd eq null or userInfo.ogCd eq ''}">
                        <th:block th:each="commonCode:${session.commonCode.get('OG')}">
                          <th:block th:if="${commonCode.itemCd == userInfo.ogCd}">
                            <td th:text="${commonCode.itemValue}"></td>
                          </th:block>
                        </th:block>
                      </th:block>
                      <th:block th:if="${userInfo.ofcCd eq null or userInfo.ofcCd eq ''}">
                        <td></td>
                      </th:block>
                      <th:block th:unless="${userInfo.ofcCd eq null or userInfo.ofcCd eq ''}">
                        <th:block th:each="commonCode:${session.commonCode.get('OFC')}">
                          <th:block th:if="${commonCode.itemCd == userInfo.ofcCd}">
                            <td th:text="${commonCode.itemValue}"></td>
                          </th:block>
                        </th:block>
                      </th:block>
                      <th:block th:if="${userInfo.titleCd eq null or userInfo.titleCd eq ''}">
                        <td></td>
                      </th:block>
                      <th:block th:unless="${userInfo.titleCd eq null or userInfo.titleCd eq ''}">
                        <th:block th:each="commonCode:${session.commonCode.get('JT')}">
                          <th:block th:if="${commonCode.itemCd == userInfo.titleCd}">
                            <td th:text="${commonCode.itemValue}"></td>
                          </th:block>
                        </th:block>
                      </th:block>
                      <td th:text="${userInfo.userNm}"></td>
                      <td th:text="${userInfo.userId}"></td>
                      <td th:text="${userInfo.dicCode}"></td>
                      <td th:text="${#temporals.format(userInfo.wrtDt, 'yyyy-MM-dd HH:mm:ss')}"></td>
                    </tr>
                    </tbody>
                  </table>
                </div>
                <div class="row justify-content-between">
                  <div class="col-auto">
                    <th:block th:if="${searchParams.userStatus eq 'USC002'}">
                      <input type="button" class="btn btn-danger" value="반려" id="companionBtn">
                    </th:block>
                    <th:block th:if="${searchParams.userStatus eq 'USC003'}">
                      <button type="button" class="btn btn-info" id="syncToKwmsAllBtn">인사시스템 정보 불러오기</button>
                    </th:block>
                  </div>
                  <div class="col-auto">
                    <nav aria-label="Page navigation">
                      <ul class="pagination">
                        <th:block th:if="${searchParams.pageIndex>3}">
                          <li class="page-item" th:data-pageindex="${(searchParams.pageIndex)-3}">
                            <a class="page-link" href="#" aria-label="Previous">
                              <span aria-hidden="true">&laquo;</span>
                            </a>
                          </li>
                        </th:block>
                        <th:block th:each="num : ${#numbers.sequence(searchParams.startNum, searchParams.endNum)}">
                          <li class="page-item" th:data-pageindex="${num}" th:classappend="${searchParams.pageIndex==num?'active':''}">
                            <a class="page-link" href="#" th:text="${num}"></a>
                          </li>
                        </th:block>
                        <th:block th:if="${searchParams.maxNum>searchParams.endNum+2}">
                          <li class="page-item" th:data-pageindex="${(searchParams.pageIndex)+3}">
                            <a class="page-link" href="#" aria-label="Next">
                              <span aria-hidden="true">&raquo;</span>
                            </a>
                          </li>
                        </th:block>
                      </ul>
                    </nav>
                  </div>
                  <div class="col-auto">
                  <th:block th:if="${searchParams.userStatus eq 'USC002'}">
                      <input type="button" class="btn btn-success" value="외사경찰 승인" id="approvalBtn">
                      <input type="button" class="btn btn-warning" value="비외사경찰 승인" id="notPoliceBtn">
                  </th:block> 
                 </div>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </main>

  <div class="modal fade" id="userEditModal" data-bs-backdrop="static" data-bs-keyboard="false" tabindex="-1" aria-labelledby="userEditModalLabel" aria-hidden="true">
    <div class="modal-dialog modal-lg modal-dialog-scrollable">
      <div class="modal-content" id="userEditModalContent">

      </div>
    </div>
  </div>
</div>
</html>