<!DOCTYPE html>
<html lang="ko" xmlns:th="http://www.thymeleaf.org">
<div class="modal-header">
  <h5 class="modal-title" id="affairViewModalLabel">견문 열람</h5>
  <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
  <div class="row">
    <div class="col-12">
      <input type="hidden" name="affairKey" id="viewModalAffairKey" th:value="${affair.affairKey}">
      <input type="hidden" name="wrtOrgan" th:value="${affair.wrtOrgan}">
      <input type="hidden" name="affairStatus" id="affairStatus" th:value="${affair.affairStatus}">
      <div class="mb-3 row">
        <label for="wrtUserNm" class="col-sm-1 col-form-label col-form-label-sm text-center">작성자</label>
        <div class="col-sm-2">
          <input type="text" class="form-control form-control-sm border-0" id="wrtUserNm" name="wrtUserNm" th:value="${affair.wrtUserNm}" readonly>
        </div>
        <label for="wrtDt" class="col-sm-1 col-form-label col-form-label-sm text-center">작성일시</label>
        <div class="col-sm-2">
          <input type="text" class="form-control form-control-sm border-0" id="wrtDt" name="wrtDt" th:value="${#temporals.format(affair.wrtDt, 'yyyy-MM-dd HH:mm')}" readonly>
        </div>
        <label class="col-sm-1 col-form-label col-form-label-sm text-center"></label>
        <div class="col-sm-2"></div>
        <label for="affairStatus" class="col-sm-1 col-form-label col-form-label-sm text-center">상태</label>
        <div class="col-sm-2">
          <th:block th:each="commonCode:${session.commonCode.get('DST')}">
            <input type="text" class="form-control form-control-sm border-0" th:if="${commonCode.itemCd eq affair.affairStatus}" th:value="${commonCode.itemValue}" readonly>
          </th:block>
        </div>
      </div>
      <div class="mb-3 row">
        <label for="reportDt" class="col-sm-1 col-form-label col-form-label-sm text-center">보고일자</label>
        <div class="col-sm-2">
          <input type="text" class="form-control form-control-sm border-0" id="reportDt" name="reportDt" th:value="${#temporals.format(affair.reportDt, 'yyyy-MM-dd')}" readonly>
        </div>
        <label for="autoDelete" class="col-sm-1 col-form-label col-form-label-sm text-center">자동삭제</label>
        <div class="col-sm-2">
          <input type="text" class="form-control form-control-sm border-0" id="autoDelete" name="autoDelete" th:value="${#temporals.format(affair.autoDelete, 'yyyy-MM-dd')}" readonly>
        </div>
        <label for="viewStatus" class="col-sm-1 col-form-label col-form-label-sm text-center">공개여부</label>
        <div class="col-sm-2">
          <th:block th:each="code:${session.commonCode.get('AVS')}">
            <th:block th:if="${code.itemCd eq affair.viewStatus}">
              <input type="text" class="form-control form-control-sm border-0" id="viewStatus" th:value="${code.itemValue}" readonly>
            </th:block>
          </th:block>
        </div>
      </div>
      <div class="mb-3 row">
        <label for="affairType1" class="col-sm-1 col-form-label col-form-label-sm text-center">분야1</label>
        <div class="col-sm-2">
          <th:block th:each="code:${session.commonCode.get('DC01')}">
            <th:block th:if="${code.itemCd eq affair.affairType1}">
              <input type="text" class="form-control form-control-sm border-0" id="affairType1" th:value="${code.itemValue}" readonly>
            </th:block>
          </th:block>
        </div>
        <label for="affairType2" class="col-sm-1 col-form-label col-form-label-sm text-center">분야2</label>
        <div class="col-sm-2">
          <th:block th:each="code:${session.commonCode.get('DC02')}">
            <th:block th:if="${code.itemCd eq affair.affairType2}">
              <input type="text" class="form-control form-control-sm border-0" id="affairType2" th:value="${code.itemValue}" readonly>
            </th:block>
          </th:block>
        </div>
        <label for="affairType3" class="col-sm-1 col-form-label col-form-label-sm text-center">분야3</label>
        <div class="col-sm-2">
          <th:block th:each="code:${session.commonCode.get('DC03')}">
            <th:block th:if="${code.itemCd eq affair.affairType3}">
              <input type="text" class="form-control form-control-sm border-0" id="affairType3" th:value="${code.itemValue}" readonly>
            </th:block>
          </th:block>
        </div>
        <label for="affairType4" class="col-sm-1 col-form-label col-form-label-sm text-center">분야4</label>
        <div class="col-sm-2">
          <th:block th:each="code:${session.commonCode.get('DC04')}">
            <th:block th:if="${code.itemCd eq affair.affairType4}">
              <input type="text" class="form-control form-control-sm border-0" id="affairType4" th:value="${code.itemValue}" readonly>
            </th:block>
          </th:block>
        </div>
      </div>
      <hr>
      <div class="row">
        <div class="col-8">
          <div class="row">
            <label for="title" class="col-sm-2 col-form-label text-center">제목</label>
            <div class="col-sm-10">
              <input type="text" class="form-control form-control-sm border-0" id="title" name="title" th:value="${affair.title}" readonly>
            </div>
          </div>
          <hr>
          <div class="row">
            <label for="contentDiv" class="col-sm-2 col-form-label text-center">내용</label>
            <div class="col-sm-10" id="contentDiv">
              <div th:utext="${affair.content}"></div>
            </div>
          </div>
          <hr>
          <div class="mb-3 row">
            <label for="hashTags" class="col-sm-2 col-form-label text-center">해시태그</label>
            <div class="col-sm-10">
              <input type="text" class="form-control form-control-sm border-0" id="hashTags" name="hashTags" th:value="${affair.hashTags}" readonly>
            </div>
          </div>
          <div class="mb-3 row">
            <label for="etc" class="col-sm-2 col-form-label text-center">비고</label>
            <div class="col-sm-10">
              <input type="text" class="form-control form-control-sm border-0" id="etc" name="etc" th:value="${affair.etc}" readonly>
            </div>
          </div>
        </div>
        <div class="col-4">
          <table class="table">
            <thead>
            <tr>
              <th>파일명</th>
              <th>사이즈</th>
            </tr>
            </thead>
            <tbody>
            <th:block th:if="${#lists.isEmpty(affair.fileList)}">
              <tr>
                <td colspan="2">파일이 없습니다.</td>
              </tr>
            </th:block>
            <th:block th:unless="${#lists.isEmpty(affair.fileList)}">
              <th:block th:each="file:${affair.fileList}">
                <tr class="fileInfoTr">
                  <td><a href="#" class="fileDownLink" data-board="affair"
                         th:data-parentkey="${file.affairKey}" th:data-fileseq="${file.fileSeq}" th:text="|${file.origNm}.${file.fileExtn}|"></a></td>
                  <td th:text="${file.fileSize}"></td>
                </tr>
              </th:block>
            </th:block>
            </tbody>
          </table>
        </div>
      </div>
      <th:block th:unless="${#lists.isEmpty(affair.rateList)}">
        <hr>
        <th:block th:each="rate:${affair.rateList}">
          <div class="row py-1">
            <div class="col-auto">
              <th:block th:each="commonCode:${session.commonCode.get('OG')}">
                <p th:if="${commonCode.itemCd eq rate.ratingOrgan}" th:text="${commonCode.itemValue}"></p>
              </th:block>
            </div>
            <div class="col-auto">
              <div class="row" th:if="${rate.sectionApprv eq null}">
                <div class="col-auto">
                  <p>결재정보가 없습니다.</p>
                </div>
              </div>
              <div class="row" th:if="${rate.sectionApprv ne null}">
                <div class="col-auto">
                  <th:block th:each="commonCode:${session.commonCode.get('DST')}">
                    <span th:if="${commonCode.itemCd eq rate.sectionApprv}" th:text="|결재결과: ${commonCode.itemValue}|"></span>
                  </th:block>
                  <span th:text="|결재자: ${rate.sectionNm}|"></span>
                </div>
                <div class="col-auto">
                  <span th:text="|결재일시: ${#temporals.format(rate.sectionApprvDt, 'yyyy-MM-dd HH:mm:ss')}|"></span>
                </div>
                <div class="col-12">
                  <span th:text="|기타의견: ${rate.sectionEtc eq null?'':rate.sectionEtc}|"></span>
                </div>
              </div>
              <div class="row" th:if="${rate.headApprv ne null}">
                <div class="col-auto" th:data-headapprv="${rate.headApprv}">
                  <th:block th:if="${rate.headApprv eq 'DST006'}">
                    <th:block th:each="commonCode:${session.commonCode.get('AAR')}">
                      <span th:if="${commonCode.itemCd eq rate.affairRate}" th:text="|견문평가: ${commonCode.itemValue} ${rate.organUp eq 'T'?'(상보)':''}|"></span>
                    </th:block>
                  </th:block>
                  <th:block th:if="${rate.headApprv eq 'DST005'}">
                    <th:block th:each="commonCode:${session.commonCode.get('DST')}">
                      <span th:if="${commonCode.itemCd eq rate.headApprv}" th:text="|결재결과: ${commonCode.itemValue}|"></span>
                    </th:block>
                  </th:block>
                  <span th:text="|결재자: ${rate.headNm}|"></span>
                </div>
                <div class="col-auto">
                  <span th:text="|결재일시: ${#temporals.format(rate.headApprvDt, 'yyyy-MM-dd HH:mm:ss')}|"></span>
                </div>
                <div class="col-12">
                  <span th:text="|기타의견: ${rate.headEtc eq null?'':rate.headEtc}|"></span>
                </div>
              </div>
            </div>
          </div>
        </th:block>
      </th:block>
    </div>
    <div class="col-12" th:if="${apprvAuth ne null}">
      <form action="#" method="post" id="apprvForm">
        <input type="hidden" name="affairKey" th:value="${affair.affairKey}">
        <th:block th:if="${(apprvAuth eq 'APC003' or apprvAuth eq 'APC004') and affair.affairStatus eq 'DST002'}">
          <input type="hidden" name="sectionApprv" id="sectionApprv">
          <div class="row">
            <div class="col-10">
              <input type="text" class="form-control form-control-sm etc" name="sectionEtc" placeholder="추가의견, 반려사유 기입">
              <input type="text" class="d-none" id="submitPrevention">
            </div>
            <div class="col-auto">
              <input type="button" class="btn btn-sm btn-success apprvBtn" data-apprvtype="section" data-affairstate="DST004" value="승인">
            </div>
            <div class="col-auto">
              <input type="button" class="btn btn-sm btn-danger apprvBtn" data-apprvtype="section" data-affairstate="DST003" value="반려">
            </div>
          </div>
        </th:block>
        <th:block th:if="${(apprvAuth eq 'APC001' or apprvAuth eq 'APC002') and affair.affairStatus eq 'DST004'}">
          <input type="hidden" name="headApprv" id="headApprv">
          <div class="row">
            <div class="col-8">
              <input type="text" class="form-control form-control-sm etc" name="headEtc" placeholder="추가의견, 반려사유 기입">
              <input type="text" class="d-none" id="submitPrevention">
            </div>
            <div class="col-auto">
              <select class="form-select form-select-sm" name="affairRate" id="affairRate">
                <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 for="organUp" class="form-check-label">상보여부</label>
              <input type="checkbox" id="organUp" name="organUp" value="T">
            </div>
            <div class="col-auto">
              <input type="button" class="btn btn-sm btn-success apprvBtn" data-apprvtype="head" data-affairstate="DST006" value="승인">
            </div>
            <div class="col-auto">
              <input type="button" class="btn btn-sm btn-danger apprvBtn" data-apprvtype="head" data-affairstate="DST005" value="반려">
            </div>
          </div>
        </th:block>
      </form>
    </div>
  </div>
</div>
<div class="modal-footer">
  <th:block th:unless="${affair.affairStatus eq 'DST004' or affair.affairStatus eq 'DST006'}"><!--승인 상태일때는 수정 불가-->
    <th:block th:if="${userSeq eq affair.wrtUserSeq or accessAuth eq 'ACC003'}"><!--작성자일 경우 수정 허용--><!--관리자일 경우 수정 허용-->
      <button type="button" class="btn btn-warning" id="editAffairBtn">수정</button>
    </th:block>
  </th:block>
  <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">닫기</button>
</div>