<!DOCTYPE html>
<html lang="ko" xmlns:th="http://www.thymeleaf.org">
<div class="modal-header">
  <h5 class="modal-title" id="planViewModalLabel">월간 계획 열람</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="planKey" id="viewModalPlanKey" th:value="${plan.planKey}">
      <input type="hidden" name="wrtOrgan" th:value="${plan.wrtOrgan}">
      <input type="hidden" name="planState" id="planState" th:value="${plan.planState}">
      <div class="mb-3 row">
        <label for="wrtUserNm" class="col-sm-1 col-form-label text-center">작성자</label>
        <div class="col-sm-2">
          <input type="text" class="form-control border-0" id="wrtUserNm" name="wrtUserNm" th:value="${plan.wrtUserNm}" readonly>
        </div>
        <label for="wrtDt" class="col-sm-1 col-form-label text-center">작성일시</label>
        <div class="col-sm-2">
          <input type="text" class="form-control border-0" id="wrtDt" name="wrtDt" th:value="${#temporals.format(plan.wrtDt, 'yyyy-MM-dd HH:mm')}" readonly>
        </div>
        <label for="planDt" class="col-sm-1 col-form-label text-center">시행일자</label>
        <div class="col-sm-2">
          <input type="text" class="form-control border-0" id="planDt" name="planDt" th:value="${#temporals.format(plan.planDt, 'yyyy-MM-dd')}" readonly>
        </div>
        <label for="planState" class="col-sm-1 col-form-label text-center">상태</label>
        <div class="col-sm-2">
          <th:block th:each="commonCode:${session.commonCode.get('DST')}">
            <input type="text" class="form-control border-0" th:if="${commonCode.itemCd eq plan.planState}" th:value="${commonCode.itemValue}" readonly>
          </th:block>
        </div>
      </div>
      <hr>
      <div class="row">
        <div class="col-8">
          <div class="mb-3 row">
            <label for="contentTitle" class="col-sm-2 col-form-label text-center">제목</label>
            <div class="col-sm-10">
              <input type="text" class="form-control border-0" id="contentTitle" name="contentTitle" th:value="${plan.contentTitle}" readonly>
            </div>
          </div>
          <hr>
          <div class="mb-3 row">
            <label for="planDiv" class="col-sm-2 col-form-label text-center">주요<br>사업계획</label>
            <div class="col-sm-10" id="planDiv">
              <th:block th:each="infoList:${plan.mainInfoList}">
                <th:block th:if="${infoList.planType eq 'S'}">
                  <input type="text" class="form-control border-0" name="planInfo" th:value="${infoList.planInfo}" readonly>
                </th:block>
              </th:block>
            </div>
          </div>
          <hr>
          <div class="mb-3 row">
            <label for="detailPlanDiv" class="col-sm-2 col-form-label text-center">사업개요<br>및<br>추진계획</label>
            <div class="col-sm-10" id="detailPlanDiv">
              <th:block th:each="infoList:${plan.mainInfoList}">
                <th:block th:if="${infoList.planType eq 'D'}">
                  <div th:utext="${infoList.planInfo}"></div>
                </th:block>
              </th:block>
            </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(plan.fileList)}">
              <tr>
                <td colspan="2">파일이 없습니다.</td>
              </tr>
            </th:block>
            <th:block th:unless="${#lists.isEmpty(plan.fileList)}">
              <th:block th:each="file:${plan.fileList}">
                <tr class="fileInfoTr">
                  <td><a href="#" class="fileDownLink" data-board="affairPlan"
                         th:data-parentkey="${file.planKey}" 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(plan.apprvList)}">
        <hr>
        <th:block th:each="apprv,cnt:${plan.apprvList}">
          <div class="row justify-content-between py-1">
            <div class="col-auto">
              <th:block th:each="commonCode:${session.commonCode.get('DST')}">
                <span th:if="${commonCode.itemCd eq apprv.state}" th:text="|결재결과: ${commonCode.itemValue}|"></span>
              </th:block>
              <span th:text="|결재자: ${apprv.userNm}|"></span>
            </div>
            <div class="col-auto">
              <span th:text="|결재일시: ${#temporals.format(apprv.saveDt, 'yyyy-MM-dd HH:mm:ss')}|"></span>
            </div>
            <div class="col-12">
              <span th:text="|기타의견: ${apprv.etc}|"></span>
            </div>
          </div>
        </th:block>
      </th:block>
    </div>
    <div class="col-12" th:if="${apprvAuth ne null}">
      <form action="#" method="post" id="apprvForm">
        <div class="row">
          <div class="col-10">
            <input type="hidden" name="planKey" id="apprvFormPlanKey">
            <input type="hidden" name="state" id="viewModalApprvValue">
            <input type="text" class="form-control form-control-sm" name="etc" placeholder="추가의견, 반려사유 기입">
            <input type="text" class="d-none" id="submitPrevention">
          </div>
          <div class="col-auto">
            <input type="button" class="btn btn-sm btn-success apprvBtn" th:data-planstate="${apprvAuth eq 'APC004'||apprvAuth eq 'APC003'?'DST004':'DST006'}" value="승인">
          </div>
          <div class="col-auto">
            <input type="button" class="btn btn-sm btn-danger apprvBtn" th:data-planstate="${apprvAuth eq 'APC004'||apprvAuth eq 'APC003'?'DST003':'DST005'}" value="반려">
          </div>
        </div>
      </form>
    </div>
  </div>
</div>
<div class="modal-footer">
  <th:block th:unless="${plan.planState eq 'DST004' or plan.planState eq 'DST006'}"><!--승인 상태일때는 수정 불가-->
    <th:block th:if="${userSeq eq plan.wrtUserSeq or accessAuth eq 'ACC003'}"><!--작성자일 경우 수정 허용--><!--관리자일 경우 수정 허용-->
      <button type="button" class="btn btn-warning" id="editPlanBtn">수정</button>
    </th:block>
  </th:block>
  <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">닫기</button>
</div>