<!DOCTYPE html>
<html lang="ko" xmlns:th="http://www.thymeleaf.org">
<div class="modal-header">
  <h5 class="modal-title" id="publicViewModalLabel">게시글 열람</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="publicKeyKey" id="viewModalPublicKey" th:value="${info.publicKey}">
      <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="${info.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(info.wrtDt, 'yyyy-MM-dd HH:mm')}" readonly>
        </div>
        <div class="col-sm-auto my-auto">
          <input type="checkbox" id="organChk" name="organChk" th:checked="${info.organChk eq 'T'}" disabled>
        </div>
        <label for="organChk" class="col-sm-2 col-form-label text-left">소속관서에만 노출</label>
      </div>
      <hr>
      <div class="row">
        <div class="col-8">
          <div class="mb-3 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 border-0" id="title" name="title" th:value="${info.title}" readonly>
            </div>
          </div>
          <hr>
          <div class="mb-3 row">
            <label for="content" class="col-sm-2 col-form-label text-center">내용</label>
            <div class="col-sm-10">
              <div id="content" th:utext="${info.content}"></div>
            </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(info.fileList)}">
              <tr>
                <td colspan="2">파일이 없습니다.</td>
              </tr>
            </th:block>
            <th:block th:unless="${#lists.isEmpty(info.fileList)}">
              <th:block th:each="file:${info.fileList}">
                <tr class="fileInfoTr">
<!--                  <td><a href="#" class="fileDownLink" data-board="monthPlan" th:data-fileseq="${file.fileSeq}" th:text="|${file.origNm}.${file.fileExtn}|"></a></td>-->
                      <td><a href="#" class="fileDownLink" data-board="publicFile"
                         th:data-parentkey="${file.publicKey}" 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>
    </div>
    <hr>
    <div class="col-12" id="commentFormHome">
      <form action="#" method="post" id="commentForm">
        <div class="row">
          <div class="col-11">
            <input type="hidden" name="publicKey" th:value="${info.publicKey}">
            <input type="hidden" name="parentComment" id="parentComment">
            <textarea id="comment" name="comment" placeholder="댓글작성"></textarea>
          </div>
          <div class="col-auto m-auto">
            <input type="button" class="btn btn-primary px-3 py-5" id="commentSaveBtn" value="작성">
          </div>
        </div>
      </form>
    </div>
    <div class="col-12 pt-3" id="commentDiv">
      <th:block th:each="comment:${info.commentList}">
        <div class="row justify-content-start commentRow">
          <input type="hidden" class="publicKey" th:value="${comment.publicKey}">
          <input type="hidden" class="commentKey" th:value="${comment.commentKey}">
          <th:block th:each="commonCode:${session.commonCode.get('OG')}">
            <div class="col-auto" th:if="${commonCode.itemCd eq comment.wrtOrgan}" th:text="${commonCode.itemValue}"></div>
          </th:block>
          <th:block th:each="commonCode:${session.commonCode.get('OFC')}">
            <div class="col-auto" th:if="${commonCode.itemCd eq comment.wrtPart}" th:text="${commonCode.itemValue}"></div>
          </th:block>
          <div class="col-auto" th:text="${comment.wrtUserNm}"></div>
          <div class="col-auto" th:text="|작성일시: ${#temporals.format(comment.wrtDt, 'yyyy-MM-dd HH:mm')}|"></div>
          <div class="col-auto">
            <button type="button" class="btn btn-sm btn-success childCommentBtn">댓글달기</button>
          </div>
          <div class="col-auto" th:if="${userSeq eq comment.wrtUserSeq}">
            <button type="button" class="btn btn-sm btn-danger deleteCommentBtn">댓글삭제</button>
          </div>
          <div class="col-12" th:utext="${comment.comment}"></div>
          <div class="col-12 childCommentDiv" style="display: none"></div>
          <hr>
        </div>
        <th:block th:each="childComment:${comment.childCommentList}">
          <div class="row justify-content-start">
            <div class="col-auto">
              <i class="bi bi-arrow-return-right" ></i>
            </div>
            <div class="col-auto">
              <div class="row justify-content-start commentRow">
                <input type="hidden" class="publicKey" th:value="${childComment.publicKey}">
                <input type="hidden" class="commentKey" th:value="${childComment.commentKey}">
                <th:block th:each="commonCode:${session.commonCode.get('OG')}">
                  <div class="col-auto" th:if="${commonCode.itemCd eq childComment.wrtOrgan}" th:text="${commonCode.itemValue}"></div>
                </th:block>
                <th:block th:each="commonCode:${session.commonCode.get('OFC')}">
                  <div class="col-auto" th:if="${commonCode.itemCd eq childComment.wrtPart}" th:text="${commonCode.itemValue}"></div>
                </th:block>
                <div class="col-auto" th:text="${childComment.wrtUserNm}"></div>
                <div class="col-auto" th:text="|작성일시: ${#temporals.format(childComment.wrtDt, 'yyyy-MM-dd HH:mm')}|"></div>
                <div class="col-auto" th:if="${userSeq eq childComment.wrtUserSeq}">
                  <button type="button" class="btn btn-sm btn-danger deleteCommentBtn">댓글삭제</button>
                </div>
                <div class="col-12" th:utext="${childComment.comment}"></div>
              </div>
            </div>
            <hr>
          </div>
        </th:block>
      </th:block>
    </div>
  </div>
</div>
<div class="modal-footer">
  <th:block th:if="${userSeq eq info.wrtUserSeq}"><!--작성자일 경우 수정 허용-->
    <button type="button" class="btn btn-warning" id="editBtn">수정</button>
  </th:block>
  <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">닫기</button>
</div>