<!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/authMgt/authMgt.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 method="get" th:action="@{/authMgt/authMgtPage}">
            <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></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" class="userSeq" th:value="${userInfo.userSeq}">
                        <td>
                          <input type="checkbox" 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>
                  <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="authEditModal" data-bs-backdrop="static" data-bs-keyboard="false" tabindex="-1" aria-labelledby="authEditModalLabel" aria-hidden="true">
    <div class="modal-dialog modal-lg modal-dialog-scrollable">
      <div class="modal-content" id="authEditModalContent">
        <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">
          <ul class="nav nav-tabs" id="userTab" role="tablist">
            <li class="nav-item" role="presentation">
              <button class="nav-link active" id="accessTab" data-bs-toggle="tab" data-bs-target="#accessTabPanel" type="button" role="tab" aria-controls="accessTabPanel" aria-selected="true">메뉴</button>
            </li>
            <li class="nav-item" role="presentation">
              <button class="nav-link" id="approvalTab" data-bs-toggle="tab" data-bs-target="#approvalTabPanel" type="button" role="tab" aria-controls="approvalTabPanel" aria-selected="false">결재</button>
            </li>
          </ul>
          <div class="tab-content border border-top-0" id="configInfo">

          </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="saveAuthBtn">저장</button>
        </div>
      </div>
    </div>
  </div>
</div>
</html>