<!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/userLog.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 active" id="requestTab" data-bs-toggle="tab" type="button" role="tab">메뉴로그</button>
      </li>
      <li class="nav-item" role="presentation">
        <button class="nav-link" id="inoutTab" data-bs-toggle="tab" type="button" role="tab">접속로그</button>
      </li>
    </ul>
    <div class="row mx-0">
      <div class="col-12 tab-content border border-top-0 p-2">
        <form method="get" th:action="@{/userMgt/userLog/requestLog}">
          <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-6">
              <div class="row justify-content-end">
                <div class="col-10">
                  <div class="row pb-1">
                    <div class="col-4">
                      <input type="text" class="form-control form-control-sm" name="contactIp" placeholder="아이피" th:value="${searchParams.contactIp}">
                    </div>
                    <div class="col-4">
                      <input type="text" class="form-control form-control-sm" name="requestUrl" placeholder="URL" th:value="${searchParams.requestUrl}">
                    </div>
                    <div class="col-4">
                      <select class="form-select form-select-sm" name="requestMethod">
                        <option value="">접근방식</option>
                        <option value="GET" th:selected="${searchParams.requestMethod eq 'GET'}">GET</option>
                        <option value="POST" th:selected="${searchParams.requestMethod eq 'POST'}">POST</option>
                      </select>
                    </div>
                  </div>
                  <div class="row">
                    <div class="col-4">
                      <input type="text" class="form-control form-control-sm" name="userBelong" placeholder="사용자" th:value="${searchParams.userBelong}">
                    </div>
                    <div class="col-8">
                      <div class="input-group w-auto input-daterange" id="dateSelectorDiv">
                        <input type="text" class="form-control form-control-sm" id="startDate" name="startDate" placeholder="시작일" autocomplete="off" readonly th:value="${searchParams.startDate}">
                        <input type="text" class="form-control form-control-sm" id="endDate" name="endDate" placeholder="종료일" autocomplete="off" readonly th:value="${searchParams.endDate}">
                      </div>
                    </div>
                  </div>
                </div>
                <div class="col-2 d-grid gap-2">
                  <input type="submit" class="btn btn-sm btn-primary mx-2" id="searchBtn" value="검색">
                </div>
              </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-hover table-bordered">
                    <thead>
                    <tr class="table-secondary">
                      <th>접속아이피</th>
                      <th>요청 URL</th>
                      <th>접근 방식</th>
                      <th>사용자</th>
                      <th>등록일</th>
                    </tr>
                    </thead>
                    <tbody class="table-group-divider">
                    <tr class="requestLogTr" th:each="log:${logList}">
                      <input type="hidden" class="contactIp" th:value="${log.contactIp}">
                      <input type="hidden" class="requestUrl" th:value="${log.requestUrl}">
                      <input type="hidden" class="requestMethod" th:value="${log.requestMethod}">
                      <input type="hidden" class="searchParams" th:value="${log.searchParams}">
                      <input type="hidden" class="handlerDescription" th:value="${log.handlerDescription}">
                      <input type="hidden" class="userBelong" th:value="${log.userBelong}">
                      <input type="hidden" class="wrtDt" th:value="${#temporals.format(log.wrtDt, 'yyyy-MM-dd HH:mm:ss')}">
                      <td th:text="${log.contactIp}"></td>
                      <td th:text="${log.requestUrl}"></td>
                      <td th:text="${log.requestMethod}"></td>
                      <td th:text="${log.userBelong}"></td>
                      <td th:text="${#temporals.format(log.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>
  </main>

  <div class="modal fade" id="requestLogModal" data-bs-backdrop="static" data-bs-keyboard="false" tabindex="-1" aria-labelledby="requestLogModalLabel" aria-hidden="true">
    <div class="modal-dialog modal-lg modal-dialog-scrollable">
      <div class="modal-content" id="requestLogModalContent">
        <div class="modal-header">
          <h5 class="modal-title" id="requestLogModalLabel">로그 상세</h5>
          <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
        </div>
        <div class="modal-body">
          <div class="row justify-content-start">
            <label for="userBelong" class="col-sm-2 col-form-label col-form-label-sm text-center pb-2">사용자</label>
            <div class="col-sm-4">
              <input type="text" class="form-control form-control-sm" id="userBelong" autocomplete="off" readonly>
            </div>
            <label for="wrtDt" class="col-sm-2 col-form-label col-form-label-sm text-center pb-2">등록일</label>
            <div class="col-sm-4">
              <input type="text" class="form-control form-control-sm" id="wrtDt" autocomplete="off" readonly>
            </div>
            <label for="contactIp" class="col-sm-2 col-form-label col-form-label-sm text-center pb-2">접속아이피</label>
            <div class="col-sm-4">
              <input type="text" class="form-control form-control-sm" id="contactIp" autocomplete="off" readonly>
            </div>
            <label for="requestUrl" class="col-sm-2 col-form-label col-form-label-sm text-center pb-2">요청 URL</label>
            <div class="col-sm-4">
              <input type="text" class="form-control form-control-sm" id="requestUrl" autocomplete="off" readonly>
            </div>
            <label for="requestMethod" class="col-sm-2 col-form-label col-form-label-sm text-center pb-2">접근방식</label>
            <div class="col-sm-4">
              <input type="text" class="form-control form-control-sm" id="requestMethod" autocomplete="off" readonly>
            </div>
            <div class="col-sm-6"></div>
            <label for="searchParams" class="col-sm-2 col-form-label col-form-label-sm text-center pb-2">검색조건</label>
            <div class="col-sm-10">
              <input type="text" class="form-control form-control-sm" id="searchParams" autocomplete="off" readonly>
            </div>
            <label for="handlerDescription" class="col-sm-2 col-form-label col-form-label-sm text-center pb-2">동작 메서드</label>
            <div class="col-sm-10">
              <input type="text" class="form-control form-control-sm" id="handlerDescription" autocomplete="off" readonly>
            </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="saveAuthBtn">저장</button>
        </div>
      </div>
    </div>
  </div>

</div>
</html>