<!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>
    <th:block th:if="${searchParams.userStatus == 'USC003'}">
    <ul class="nav nav-tabs" id="boardTab" role="tablist">
      <li class="nav-item" role="presentation">
        <button class="nav-link active" id="contentTab" data-bs-toggle="tab" data-bs-target="#contentDiv" type="button" role="tab">승인목록</button>
      </li>
      <li class="nav-item" role="presentation">
        <button class="nav-link" id="logTab" data-bs-toggle="tab" data-bs-target="#logDiv" type="button" role="tab">승인대기</button>    	
      </li>
    </ul>
    </th:block>
    <th:block th:unless="${searchParams.userStatus == 'USC003'}">
    <ul class="nav nav-tabs" id="boardTab" role="tablist">
      <li class="nav-item" role="presentation">
        <button class="nav-link" id="contentTab" data-bs-toggle="tab" data-bs-target="#contentDiv" type="button" role="tab">승인목록</button>
      </li>
      <li class="nav-item" role="presentation">
        <button class="nav-link active" id="logTab" data-bs-toggle="tab" data-bs-target="#logDiv" type="button" role="tab">승인대기</button>    	
      </li>
    </ul>
    </th:block>
    <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 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" 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">
                    <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>
                        <th> <input type="checkbox" id="chk-all" class="userInfoCheckBox"></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}">                      
                        <td>
                          <input type="checkbox" id="userChk" name="userChk" class="userInfoCheckBox" th:value="${userInfo.userSeq}">
                        </td>
                        <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:each="commonCode:${session.commonCode.get('OFC')}">
                          <th:block th:if="${commonCode.itemCd == userInfo.ofcCd}">
                            <td th:text="${commonCode.itemValue}"></td>
                          </th:block>
                        </th:block>
                        <td></td>
                        <td th:text="${userInfo.userNm}"></td>
                        <td th:text="${userInfo.userId}"></td>
                        <td th:text="${#temporals.format(userInfo.wrtDt, 'yyyy-MM-dd HH:mm:ss')}"></td>
                      </tr>
                      </tbody>
                    </table>
                  </div>
                  <th:block th:if="${searchParams.userStatus == 'USC002'}">
                  <div class="col-auto">
                      <input type="button" class="btn btn-success" value="승인" id="approvalBtn">
                      <input type="button" class="btn btn-success" value="반려" id="companionBtn">
                  </div>
                  </th:block>
                  <div class="row justify-content-center">
                    <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>
                </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 class="modal-header">
          <h5 class="modal-title" id="menuEditModalLabel">외사경찰 수정</h5>
          <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
        </div>
        <div class="modal-body">
          <div class="tab-content border border-top-0" id="configInfo">

          </div>
        </div>
        <div class="modal-footer">
          <button type="button" class="btn" id="deleteBtn" style='background-color : red;float:left;'>삭제</button>
          <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">닫기</button>
          <button type="button" class="btn btn-primary" id="updateBtn">저장</button>
        </div>
      </div>
    </div>
  </div>
</div>
</html>