<!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/igActivities/fpiMgt/affairPlan.js}"></script>
  <script type="text/javascript" th:src="@{/js/igActivities/fpiMgt/commitPlan.js}"></script>
</th:block>
<div layout:fragment="content">
  <main class="pt-3">
    <p>첩보수집활동 > 외사경찰 견문관리 > 계획수립</p>
    <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">
          <ul class="nav nav-tabs" id="userTab" role="tablist">
            <li class="nav-item" role="presentation">
              <button class="nav-link" id="monthPlanTab" data-bs-toggle="tab" data-bs-target="#monthPlanPanel" type="button" role="tab" aria-controls="monthPlanPanel" aria-selected="false">월간 계획</button>
            </li>
            <li class="nav-item" role="presentation">
              <button class="nav-link" id="apprvStayTab" data-bs-toggle="tab" data-bs-target="#apprvStayPanel" type="button" role="tab" aria-controls="apprvStayPanel" aria-selected="false">결재대기목록</button>
            </li>
            <li class="nav-item" role="presentation">
              <button class="nav-link active" id="apprvCommitTab" data-bs-toggle="tab" data-bs-target="#apprvCommitPanel" type="button" role="tab" aria-controls="apprvCommitPanel" aria-selected="true">결재처리목록</button>
            </li>
          </ul>
          <div class="tab-content border border-top-0 p-2" id="planContent">
            <form method="get" th:action="@{/fpiMgt/apprvCommitPage}">
              <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 eq num*10}"></option>
                    </th:block>
                  </select>
                </div>
                <div class="col-auto">
                  <div class="row justify-content-end">
                    <div class="col-auto" th:if="${accessAuth eq 'ACC003'}">
                      <select class="form-select form-select-sm" name="wrtOrgan">
                        <option value="">관서 선택</option>
                        <th:block th:each="commonCode:${session.commonCode.get('OG')}">
                          <th:block th:if="${#lists.contains(mgtOrganList, commonCode.itemCd)}">
                            <option th:value="${commonCode.itemCd}" th:text="${commonCode.itemValue}" th:selected="${commonCode.itemCd eq searchParams.wrtOrgan}"></option>
                          </th:block>
                        </th:block>
                      </select>
                    </div>
                    <div class="col-auto">
                      <input type="text" class="form-control form-control-sm" placeholder="제목" name="contentTitle" th:value="${searchParams.contentTitle}">
                    </div>
                    <div class="col-auto" th:if="${accessAuth eq 'ACC003'}">
                      <input type="text" class="form-control form-control-sm" placeholder="작성자" name="wrtUserNm" th:value="${searchParams.wrtUserNm}">
                    </div>
                    <div class="col-auto">
                      <select class="form-select form-select-sm" name="planState">
                        <option value="">상태 선택</option>
                        <th:block th:each="commonCode:${session.commonCode.get('DST')}">
                          <option th:value="${commonCode.itemCd}" th:text="${commonCode.itemValue}" th:selected="${commonCode.itemCd eq searchParams.planState}"></option>
                        </th:block>
                      </select>
                    </div>
                    <div class="col-4">
                      <div class="input-group w-auto input-daterange" id="dateSelectorDiv">
                        <select class="form-select form-select-sm" name="dateSelector">
                          <option value="">조건선택</option>
                          <option value="planDt" th:selected="${searchParams.dateSelector eq 'planDt'}">시행일</option>
                          <option value="wrtDt" th:selected="${searchParams.dateSelector eq 'wrtDt'}">작성일</option>
                        </select>
                        <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>
                    <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-hover">
                        <thead>
                        <tr>
                          <th></th>
                          <th>제목</th>
                          <th>시행일자</th>
                          <th>관서</th>
                          <th>부서</th>
                          <th>작성자</th>
                          <th>작성일시</th>
                          <th>첨부파일</th>
                          <th>상태</th>
                        </tr>
                        </thead>
                        <tbody>
                        <tr class="planTr" th:each="plan:${planList}">
                          <input type="hidden" class="planKey" th:value="${plan.planKey}">
                          <td><input type="checkbox" class="trChkBox"></td>
                          <td th:text="${plan.contentTitle}"></td>
                          <td th:text="${#temporals.format(plan.planDt, 'yyyy-MM-dd')}"></td>
                          <th:block th:each="commonCode:${session.commonCode.get('OG')}">
                            <td th:if="${plan.wrtOrgan eq commonCode.itemCd}" th:text="${commonCode.itemValue}"></td>
                          </th:block>
                          <th:block th:each="commonCode:${session.commonCode.get('OFC')}">
                            <td th:if="${plan.wrtPart eq commonCode.itemCd}" th:text="${commonCode.itemValue}"></td>
                          </th:block>
                          <td th:text="${plan.wrtUserNm}"></td>
                          <td th:text="${#temporals.format(plan.wrtDt, 'yyyy-MM-dd HH:mm')}"></td>
                          <td th:text="${plan.fileCnt eq null?'파일 없음':#strings.concat(plan.fileCnt,' 건')}"></td>
                          <td th:if="${plan.planState eq 'DST001'}">임시저장</td>
                          <td th:if="${plan.planState eq 'DST002'}">결재대기</td>
                          <td th:if="${plan.planState eq 'DST003'}">계장반려</td>
                          <td th:if="${plan.planState eq 'DST004'}">계장결재</td>
                          <td th:if="${plan.planState eq 'DST005'}">부장반려</td>
                          <td th:if="${plan.planState eq 'DST006'}">부장결재</td>
                        </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 eq 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">
                        <input type="button" class="btn btn-success" value="등록" id="addPlanBtn" th:unless="${accessAuth eq 'ACC001'}">
                      </div>
                    </div>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </main>

  <div class="modal fade" id="planViewModal" data-bs-backdrop="static" data-bs-keyboard="false" tabindex="-1" aria-labelledby="planViewModalLabel" aria-hidden="true">
    <div class="modal-dialog modal-xl modal-dialog-scrollable">
      <div class="modal-content" id="planViewBody">

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