<!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/faRpt/faRpt.js}"></script>
  <script type="text/javascript" th:src="@{/js/modal/userModal.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" th:classappend="${searchParams.activeTab eq 'send'?' active':''}" id="sendTab" data-bs-toggle="tab" type="button" role="tab">송신 목록</button>
            </li>
            <li class="nav-item" role="presentation">
              <button class="nav-link" th:classappend="${searchParams.activeTab eq 'receive'?' active':''}" id="receiveTab" data-bs-toggle="tab" type="button" role="tab">수신 목록</button>
            </li>
            <th:block th:if="${accessAuth eq 'ACC003'}">
              <li class="nav-item" role="presentation" >
                <button class="nav-link" th:classappend="${searchParams.activeTab eq 'all'?' active':''}" id="allTab" data-bs-toggle="tab" type="button" role="tab">전체 목록</button>
              </li>
            </th:block>
          </ul>
          <div class="tab-content border border-top-0 p-2">
            <form method="get" th:action="${searchUrl}">
              <input type="hidden" name="activeTab" id="activeTab" th:value="${searchParams.activeTab}">
              <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 eq num*10}"></option>
                    </th:block>
                  </select>
                </div>
                <div class="col-auto">
                  <div class="row justify-content-end">
                    <div class="col-auto" th:if="${searchParams.activeTab ne 'send'}">
                      <select class="form-select form-select-sm" name="wrtOrgan">
                        <option value="">관서 선택</option>
                        <th:block th:each="commonCode:${session.commonCode.get('OG')}">
                          <option th:value="${commonCode.itemCd}" th:text="${commonCode.itemValue}" th:selected="${commonCode.itemCd eq searchParams.wrtOrgan}"></option>
                        </th:block>
                      </select>
                    </div>
                    <div class="col-auto">
                      <input type="text" class="form-control form-control-sm" placeholder="제목" name="title" th:value="${searchParams.title}">
                    </div>
                    <div class="col-auto">
                      <input type="text" class="form-control form-control-sm" placeholder="해시태그" name="hashTags" th:value="${searchParams.hashTags}">
                    </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">
                      <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>
                    <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-bordered table-hover">
                        <thead>
                        <tr class="table-secondary">
                          <th></th>
                          <th th:if="${searchParams.status ne 'receive'}">상태</th>
                          <th>분류</th>
                          <th>제목</th>
                          <th>관서</th>
                          <th>부서</th>
                          <th>작성자</th>
                          <th>작성일시</th>
                          <th>첨부파일</th>
                          <th>열람수</th>
                        </tr>
                        </thead>
                        <tbody class="table-group-divider">
                        <tr class="faRptTr" th:each="faRpt:${faRptList}">
                          <input type="hidden" class="faRptKey" th:value="${faRpt.faRptKey}">
                          <td><input type="checkbox" class="trChkBox"></td>
                          <td th:if="${faRpt.status ne 'receive'}">
                            <th:block th:each="commonCode:${session.commonCode.get('DST')}">
                              <th:text th:if="${commonCode.itemCd eq faRpt.status}" th:text="${commonCode.itemValue}"></th:text>
                            </th:block>
                          </td>
                          <td>
                            <th:block th:each="commonCode:${session.commonCode.get('FRC')}">
                              <th:text th:if="${commonCode.itemCd eq faRpt.faRptType}" th:text="${commonCode.itemValue}"></th:text>
                            </th:block>
                          </td>
                          <td th:text="${faRpt.title}"></td>
                          <th:block th:each="commonCode:${session.commonCode.get('OG')}">
                            <td th:if="${faRpt.wrtOrgan eq commonCode.itemCd}" th:text="${commonCode.itemValue}"></td>
                          </th:block>
                          <th:block th:each="commonCode:${session.commonCode.get('OFC')}">
                            <td th:if="${faRpt.wrtPart eq commonCode.itemCd}" th:text="${commonCode.itemValue}"></td>
                          </th:block>
                          <td th:text="${faRpt.wrtUserNm}"></td>
                          <td th:text="${#temporals.format(faRpt.wrtDt, 'yyyy-MM-dd HH:mm')}"></td>
                          <td th:text="${faRpt.fileCnt eq null?'파일 없음':#strings.concat(faRpt.fileCnt,' 건')}"></td>
                          <td th:text="|${faRpt.readCnt}/${faRpt.userCnt}|"></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="addFaRptBtn" th:unless="${accessAuth eq 'ACC001'}">
                      </div>
                    </div>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </main>

  <div class="modal fade" id="faRptEditModal" data-bs-backdrop="static" data-bs-keyboard="false" tabindex="-1" aria-labelledby="faRptEditModalLabel" aria-hidden="true">
    <div class="modal-dialog modal-xxl modal-dialog-scrollable">
      <div class="modal-content" id="faRptEditModalContent">

      </div>
    </div>
  </div>
  <div class="modal fade" id="faRptViewModal" data-bs-backdrop="static" data-bs-keyboard="false" tabindex="-1" aria-labelledby="faRptViewModalLabel" aria-hidden="true">
    <div class="modal-dialog modal-xl modal-dialog-scrollable">
      <div class="modal-content" id="faRptViewBody">

      </div>
    </div>
  </div>
  <div class="modal fade" id="userModal" data-bs-backdrop="static" data-bs-keyboard="false" tabindex="-1" aria-labelledby="userModalLabel" aria-hidden="true">
    <div class="modal-dialog modal-xl modal-dialog-scrollable">
      <div class="modal-content">
        <div class="modal-header">
          <h5 class="modal-title" id="menuModalLabel">수신자 검색</h5>
          <input type="hidden" id="modalUrl" value="/modal/userModal">
          <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
        </div>
        <div class="modal-body" id="subModalBody">
          <div class="row">
            <div class="col-12">
              <form method="get" action="#" id="modalSearchForm">
                <input type="hidden" name="pageIndex" id="modalPageIndex" value="1">
                <input type="hidden" name="rowCnt" value="10">
              </form>
            </div>
          </div>
        </div>
        <div class="modal-footer">
          <button type="button" class="btn btn-primary" id="getMenuBtn">추가</button>
          <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">닫기</button>
        </div>
      </div>
    </div>
  </div>
</div>
</html>