<!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/user/modifyRequestList.js}"></script>
</th:block>
<div layout:fragment="content">
  <main class="pt-3">
    <input type="hidden" name="_csrf_header" th:value="${_csrf.headerName}"/>
    <input type="hidden" th:name="${_csrf.parameterName}" th:value="${_csrf.token}"/>
    <h4>수정 요청 현황</h4>
    <div class="row mx-0">
      <div class="col-12 card">
        <div class="card-body">
          <div class="row justify-content-start">
            <div class="col-7">
              <!--검색 form-->
              <form method="get" th:action="@{/info/modifyRequestList}">
                <input type="hidden" name="pageIndex" id="pageIndex" th:value="${searchParams.pageIndex}">
                <div class="row">
                  <div class="col-12 card">
                    <div class="row pt-1">
                      <div class="col-auto">
                        <div class="row my-2">
                          <label for="rowCnt" class="col-sm-auto col-form-label">데이터 수</label>
                          <div class="col-sm-auto">
                            <select class="form-select form-control-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>
                          <label for="title" class="col-sm-auto col-form-label">제목</label>
                          <div class="col-sm-auto">
                            <input type="text" class="form-control form-control-sm" id="title" name="title" th:value="${searchParams.title}">
                          </div>
                          <th:block th:if="${searchParams.userRole=='ADMIN'}">
                            <label for="createName" class="col-sm-auto col-form-label">작성자</label>
                            <div class="col-sm-auto">
                              <input type="text" class="form-control form-control-sm" id="createName" name="createName" th:value="${searchParams.createName}">
                            </div>
                          </th:block>
                        </div>
                        <div class="row my-2">
                          <label for="requestType" class="col-sm-auto col-form-label">구분</label>
                          <div class="col-sm-auto">
                            <select class="form-select form-control-sm" name="requestType" id="requestType">
                              <option value="">전체</option>
                              <option value="userInfo" th:selected="${searchParams.requestType=='userInfo'}">계정정보</option>
                              <option value="categoryRole" th:selected="${searchParams.requestType=='categoryRole'}">권한정보</option>
                              <option value="etc" th:selected="${searchParams.requestType=='etc'}">기타</option>
                            </select>
                          </div>
                          <label for="status" class="col-sm-auto col-form-label">상태</label>
                          <div class="col-sm-auto">
                            <select class="form-select form-control-sm" name="status" id="status">
                              <option value="">전체</option>
                              <option value="wait" th:selected="${searchParams.status=='wait'}">대기</option>
                              <option value="approval" th:selected="${searchParams.status=='approval'}">승인</option>
                              <option value="dinial" th:selected="${searchParams.status=='dinial'}">거부</option>
                            </select>
                          </div>
                          <label for="startDate" class="col-sm-auto col-form-label">작성일</label>
                          <div class="col-sm-5">
                            <div class="col-auto input-group w-auto input-daterange" id="dateSelectorDiv">
                              <input type="text" class="form-control form-control-sm" id="startDate" name="startDate" placeholder="시작일" autocomplete="off" th:value="${searchParams.startDate}" readonly>
                              <input type="text" class="form-control form-control-sm" id="endDate" name="endDate" placeholder="종료일" autocomplete="off" th:value="${searchParams.endDate}" readonly>
                            </div>
                          </div>
                        </div>
                      </div>
                      <div class="col-auto my-auto px-0">
                        <input type="submit" class="btn btn-primary py-4" id="searchBtn" value="검색">
                      </div>
                    </div>
                  </div>
                </div>
              </form>
              <div class="row-cols-6">
                <table class="table table-striped">
                  <thead>
                  <tr>
                    <th></th>
                    <th>구분</th>
                    <th>제목</th>
                    <th>상태</th>
                    <th>작성자</th>
                    <th>생성일</th>
                  </tr>
                  </thead>
                  <tbody>
                  <tr class="modifyRequestTr" th:each="modifyRequest:${modifyRequestList}">
                    <td>
                      <input type="checkbox" class="modifyRequestCheckBox" th:value="${modifyRequest.requestSeq}">
                    </td>
                    <td>
                      <th:block th:if="${modifyRequest.requestType=='userInfo'}">계정정보</th:block>
                      <th:block th:if="${modifyRequest.requestType=='categoryRole'}">권한정보</th:block>
                      <th:block th:if="${modifyRequest.requestType=='etc'}">기타</th:block>
                    </td>
                    <td th:text="${modifyRequest.title}"></td>
                    <td>
                      <th:block th:if="${modifyRequest.status=='delete'}">삭제</th:block>
                      <th:block th:if="${modifyRequest.status=='wait'}">대기</th:block>
                      <th:block th:if="${modifyRequest.status=='dinial'}">거부</th:block>
                      <th:block th:if="${modifyRequest.status=='approval'}">승인</th:block>
                    </td>
                    <td th:text="${modifyRequest.createName}"></td>
                    <th:block th:if="${#dates.format(#dates.createNow(), 'yyyy-MM-dd')} == ${#temporals.format(modifyRequest.createDate, 'yyyy-MM-dd')}">
                      <td th:text="${#temporals.format(modifyRequest.createDate, 'HH:mm:ss')}"></td>
                    </th:block>
                    <th:block th:unless="${#dates.format(#dates.createNow(), 'yyyy-MM-dd')} == ${#temporals.format(modifyRequest.createDate, 'yyyy-MM-dd')}">
                      <td th:text="${#temporals.format(modifyRequest.createDate, 'yyyy-MM-dd')}"></td>
                    </th:block>
                  </tr>
                  </tbody>
                </table>
              </div>
              <div class="row justify-content-between">
                <div class="col-auto"></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">
                  <a class="btn btn-warning mb-2" href="/info/modifyRequestWrite" th:if="${searchParams.userRole=='USER'}"> 수정 요청</a>
                </div>
              </div>
            </div>
            <div class="col-5">
              <div class="card" id="requestDetailDiv">
                <h3 class="p-5">왼쪽 목록에서 선택해주세요.</h3>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </main>
</div>
</html>