<!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/affair/affairMgt.js}"></script>
</th:block>
<div layout:fragment="content">
  <main class="pt-3">
    <p th:text="${#strings.concat('첩보수집활동 > ', (searchParams.affairCategory eq 'CAT215'?'보안경찰':'보안첩보망'), ' 견문관리 > 견문관리')}"></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="${page eq 'main'?' active':''}" id="affairTab" data-bs-toggle="tab" type="button" role="tab">전체 목록</button>
            </li>
            <li class="nav-item" role="presentation">
              <button class="nav-link" th:classappend="${page eq 'stay'?' active':''}" id="stayTab" data-bs-toggle="tab" type="button" role="tab">결재대기목록</button>
            </li>
            <li class="nav-item" role="presentation">
              <button class="nav-link" th:classappend="${page eq 'commit'?' active':''}" id="commitTab" data-bs-toggle="tab" type="button" role="tab">결재처리목록</button>
            </li>
          </ul>
          <div class="tab-content border border-top-0 p-2">
            <form method="get" th:action="${searchUrl}">
              <input type="hidden" name="affairCategory" id="affairCategory" th:value="${searchParams.affairCategory}">
              <input type="hidden" name="pageIndex" id="pageIndex" th:value="${searchParams.pageIndex}">
              <div class="row pe-3 py-1">
                <div class="col-1">
                  <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-10">
                  <div class="row justify-content-end pb-1" th:if="${accessAuth eq 'ACC003'}">
                    <div class="col-auto">
                      <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="wrtUserNm" th:value="${searchParams.wrtUserNm}">
                    </div>
                  </div>
                  <div class="row justify-content-end pb-1">
                    <div class="col-auto">
                      <select class="form-select form-select-sm" name="affairType1">
                        <option value="">분야1 선택</option>
                        <th:block th:each="commonCode:${session.commonCode.get('DC01')}">
                          <option th:value="${commonCode.itemCd}" th:text="${commonCode.itemValue}" th:selected="${commonCode.itemCd eq searchParams.affairType1}"></option>
                        </th:block>
                      </select>
                    </div>
                    <div class="col-auto">
                      <select class="form-select form-select-sm" name="affairType2">
                        <option value="">분야2 선택</option>
                        <th:block th:each="commonCode:${session.commonCode.get('DC02')}">
                          <option th:value="${commonCode.itemCd}" th:text="${commonCode.itemValue}" th:selected="${commonCode.itemCd eq searchParams.affairType2}"></option>
                        </th:block>
                      </select>
                    </div>
                    <div class="col-auto">
                      <select class="form-select form-select-sm" name="affairType3">
                        <option value="">분야3 선택</option>
                        <th:block th:each="commonCode:${session.commonCode.get('DC03')}">
                          <option th:value="${commonCode.itemCd}" th:text="${commonCode.itemValue}" th:selected="${commonCode.itemCd eq searchParams.affairType3}"></option>
                        </th:block>
                      </select>
                    </div>
                    <div class="col-auto">
                      <select class="form-select form-select-sm" name="affairType4">
                        <option value="">분야4 선택</option>
                        <th:block th:each="commonCode:${session.commonCode.get('DC04')}">
                          <option th:value="${commonCode.itemCd}" th:text="${commonCode.itemValue}" th:selected="${commonCode.itemCd eq searchParams.affairType4}"></option>
                        </th:block>
                      </select>
                    </div>
                  </div>
                  <div class="row justify-content-end">
                    <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">
                      <select class="form-select form-select-sm" name="affairStatus">
                        <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.affairStatus}"></option>
                        </th:block>
                      </select>
                    </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>
                  </div>
                </div>
                <div class="col-1 d-grid gap-2">
                  <input type="submit" class="btn btn-lg btn-primary col-auto" id="searchBtn" value="검색">
                </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>분야1</th>
                          <th>분야2</th>
                          <th>분야3</th>
                          <th>분야4</th>
                          <th>제목</th>
                          <th>관서</th>
                          <th>부서</th>
                          <th>작성자</th>
                          <th>작성일시</th>
                          <th>첨부파일</th>
                          <th>상태</th>
                          <th:block th:if="${page eq 'stay' and apprvAuth ne null}">
                            <th>평가</th>
                          </th:block>
                          <th:block th:if="${page eq 'commit'}">
                            <th>평가</th>
                            <th>상보</th>
                          </th:block>
                        </tr>
                        </thead>
                        <tbody>
                        <tr class="affairTr" th:each="affair:${affairList}">
                          <input type="hidden" class="affairKey" th:value="${affair.affairKey}">
                          <td><input type="checkbox" class="trChkBox"></td>
                          <th:block th:each="commonCode:${session.commonCode.get('DC01')}">
                            <td th:if="${affair.affairType1 eq commonCode.itemCd}" th:text="${commonCode.itemValue}"></td>
                          </th:block>
                          <th:block th:each="commonCode:${session.commonCode.get('DC02')}">
                            <td th:if="${affair.affairType2 eq commonCode.itemCd}" th:text="${commonCode.itemValue}"></td>
                          </th:block>
                          <th:block th:each="commonCode:${session.commonCode.get('DC03')}">
                            <td th:if="${affair.affairType3 eq commonCode.itemCd}" th:text="${commonCode.itemValue}"></td>
                          </th:block>
                          <th:block th:each="commonCode:${session.commonCode.get('DC04')}">
                            <td th:if="${affair.affairType4 eq commonCode.itemCd}" th:text="${commonCode.itemValue}"></td>
                          </th:block>
                          <td th:text="${affair.title}"></td>
                          <th:block th:each="commonCode:${session.commonCode.get('OG')}">
                            <td th:if="${affair.wrtOrgan eq commonCode.itemCd}" th:text="${commonCode.itemValue}"></td>
                          </th:block>
                          <th:block th:each="commonCode:${session.commonCode.get('OFC')}">
                            <td th:if="${affair.wrtPart eq commonCode.itemCd}" th:text="${commonCode.itemValue}"></td>
                          </th:block>
                          <td th:text="${affair.wrtUserNm}"></td>
                          <td th:text="${#temporals.format(affair.wrtDt, 'yyyy-MM-dd HH:mm')}"></td>
                          <td th:text="${affair.fileCnt eq null?'파일 없음':#strings.concat(affair.fileCnt,' 건')}"></td>
                          <th:block th:each="commonCode:${session.commonCode.get('DST')}">
                            <td th:if="${affair.affairStatus eq commonCode.itemCd}" th:text="${commonCode.itemValue}"></td>
                          </th:block>
                          <th:block th:if="${page eq 'stay'}">
                            <th:block th:if="${apprvAuth eq 'APC004' or apprvAuth eq 'APC003'}">
                              <td class="apprvTd">
                                <input type="hidden" class="affairKey" th:value="${affair.affairKey}">
                                <input type="radio" class="apprvChkbox" th:id="|apprvChkbox${affair.affairKey}DST004|" th:name="|apprvChkbox${affair.affairKey}|" value="DST004">
                                <label th:for="|apprvChkbox${affair.affairKey}DST004|">결재</label>
                                <input type="radio" class="apprvChkbox" th:id="|apprvChkbox${affair.affairKey}DST003|" th:name="|apprvChkbox${affair.affairKey}|" value="DST003">
                                <label th:for="|apprvChkbox${affair.affairKey}DST003|">반려</label>
                                <input type="radio" th:id="|apprvChkbox${affair.affairKey}|" th:name="|apprvChkbox${affair.affairKey}|" value="" checked>
                                <label th:for="|apprvChkbox${affair.affairKey}|">해제</label>
                              </td>
                            </th:block>
                            <th:block th:if="${apprvAuth eq 'APC002' or apprvAuth eq 'APC001'}">
                              <td class="apprvTd">
                                <input type="hidden" class="affairKey" th:value="${affair.affairKey}">
                                <div class="row justify-content-center">
                                  <div class="col-auto">
                                    <input type="radio" class="apprvChkbox" th:id="|apprvChkbox${affair.affairKey}DST006|" th:name="|apprvChkbox${affair.affairKey}|" value="DST006">
                                    <label th:for="|apprvChkbox${affair.affairKey}DST006|">결재</label>
                                    <input type="radio" class="apprvChkbox" th:id="|apprvChkbox${affair.affairKey}DST005|" th:name="|apprvChkbox${affair.affairKey}|" value="DST005">
                                    <label th:for="|apprvChkbox${affair.affairKey}DST005|">반려</label>
                                    <input type="radio" th:id="|apprvChkbox${affair.affairKey}|" th:name="|apprvChkbox${affair.affairKey}|" value="" checked>
                                    <label th:for="|apprvChkbox${affair.affairKey}|">해제</label>
                                  </div>
                                  <div class="col-auto">
                                    <select class="form-select form-select-sm ratingSelector" disabled>
                                      <option value="">선택</option>
                                      <th:block th:each="ratingCode:${ratingCodeList}">
                                        <option th:value="${ratingCode.itemCd}" th:text="${ratingCode.itemValue}"></option>
                                      </th:block>
                                    </select>
                                  </div>
                                  <div class="col-auto" th:unless="${userOrgan eq 'OG001'}">
                                    <label th:for="|organUp${affair.affairKey}|">상보</label>
                                    <input type="checkbox" class="organUpChkBox" th:id="|organUp${affair.affairKey}|" value="T" disabled>
                                  </div>
                                </div>
                              </td>
                            </th:block>
                          </th:block>
                          <th:block th:if="${page eq 'commit'}">
                            <th:block th:if="${affair.affairStatus eq 'DST006'}">
                              <th:block th:each="ratingCode:${session.commonCode.get('AAR')}">
                                <td th:if="${ratingCode.itemCd eq affair.affairRate}" th:text="${ratingCode.itemValue}"></td>
                              </th:block>
                              <td th:text="${affair.organUp eq 'T'?'O':'X'}"></td>
                            </th:block>
                            <th:block th:unless="${affair.affairStatus eq 'DST006'}">
                              <td></td>
                              <td></td>
                            </th:block>
                          </th:block>
                        </tr>
                        </tbody>
                      </table>
                    </div>
                    <div class="row justify-content-between">
                      <div class="col-auto">
                        <input type="button" class="btn btn-success" value="등록" id="addAffairBtn" th:unless="${accessAuth eq 'ACC001'}">
                      </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-warning" value="결재" id="tableApprvBtn" th:if="${page eq 'stay' and apprvAuth ne null}" th:data-apprvauth="${apprvAuth}">
                      </div>
                    </div>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </main>

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

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

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