<!DOCTYPE html>
<html lang="ko" xmlns:th="http://www.thymeleaf.org">
<div class="modal-header">
  <h5 class="modal-title" id="faRptEditModalLabel" th:text="${sri.faSriKey eq null?'SRI 작성':'SRI 수정'}"></h5>
  <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body" id="faRptEditBody">
  <form action="#" method="post" id="sriEditForm">
    <input type="hidden" name="_csrf_header" th:value="${_csrf.headerName}"/>
    <input type="hidden" th:name="${_csrf.parameterName}" th:value="${_csrf.token}"/>
    <input type="hidden" name="faSriKey" th:value="${sri.faSriKey}">
    <input type="hidden" name="wrtOrgan" th:value="${sri.wrtOrgan}">
    <input type="hidden" name="wrtPart" th:value="${sri.wrtPart}">
    <input type="hidden" name="wrtUserSeq" th:value="${sri.wrtUserSeq}">
    <input type="hidden" name="wrtTitle" th:value="${sri.wrtTitle}">
    <input type="hidden" name="status" id="status" th:value="${sri.status}">
    <input type="hidden" name="refKey" th:value="${sri.refKey}">
    <div class="row">
      <div class="col-8">
        <div class="mb-3 row">
          <label for="wrtUserNm" class="col-sm-2 col-form-label col-form-label-sm text-center">작성자</label>
          <div class="col-sm-4">
            <input type="text" class="form-control form-control-sm" id="wrtUserNm" name="wrtUserNm" th:value="${sri.wrtUserNm}" readonly>
          </div>
          <label for="wrtDt" class="col-sm-2 col-form-label col-form-label-sm text-center">작성일시</label>
          <div class="col-sm-4">
            <input type="text" class="form-control form-control-sm" id="wrtDt" name="wrtDt" th:value="${#temporals.format(sri.wrtDt, 'yyyy-MM-dd HH:mm')}" readonly>
          </div>
        </div>
        <th:block th:if="${sri.refKey eq null}">
        <div class="mb-3 row">
          <label for="faRptType" class="col-sm-2 col-form-label col-form-label-sm text-center">분류</label>
          <div class="col-sm-4">
            <select class="form-select form-select-sm" id="faSriType" name="faSriType">
              <option value="">선택해주세요.</option>
              <th:block th:each="SriCategory:${SriCategoryList}">
                <option th:value="${SriCategory.itemCd}" th:text="${SriCategory.itemValue}" th:selected="${SriCategory.itemCd eq sri.faSriType}"></option>
              </th:block>
            </select>
          </div>
	          <label for="faRptType" class="col-sm-2 col-form-label col-form-label-sm text-center">제출기한</label>
	          <div class="col-sm-4">
	            <input type="text" class="form-control form-control-sm" id="faSriEdate" name="faSriEdate" th:value="${sri.faSriEdate}" readonly>
	          </div>
        </div>
        </th:block>
        <div class="mb-3 row">
          <label for="title" class="col-sm-2 col-form-label col-form-label-sm text-center">제목</label>
          <div class="col-sm-10">
          <th:block th:if="${sri.refKey eq null}">
            <input type="text" class="form-control form-control-sm" id="title" name="title" th:value="${sri.title}">
          </th:block>
          <th:block th:unless="${sri.refKey eq null}">
          	<input type="text" class="form-control form-control-sm" id="title" name="title" th:value="[회신]">
          </th:block>
          </div>
        </div>
        <div class="mb-3 row justify-content-center">
          <label for="content" class="col-sm-2 col-form-label col-form-label-sm text-center">내용</label>
          <div class="col-sm-10">
	        <div id="editor"></div>
	        	<textarea id="content" class="d-none" th:utext="${sri.content}"></textarea>
	        </div>
        </div>
        <div class="row mb-3">
          <label for="fileInputer" class="col-sm-2 col-form-label col-form-label-sm text-center">업로드 자료</label>
          <div class="col-sm-10" style="min-height: 70px;">
            <div class="w-100 h-100 border border-info rounded text-center" id="uploadDiv">
              <th:block th:if="${#arrays.isEmpty(sri.fileList)}">
                <br>파일을 업로드 해주세요.
              </th:block>
              <th:block th:unless="${#arrays.isEmpty(sri.fileList)}">
                <div class='row-col-6' th:each="sriFile:${sri.fileList}">
                  <span th:data-fileseq="${sriFile.fileSeq}" th:text="|${sriFile.origNm}.${sriFile.fileExtn} ${sriFile.fileSize}|"></span>
                  <a href='#' class='uploadedFileDelete text-danger text-decoration-none'>삭제</a>
                </div>
              </th:block>
            </div>
          </div>
          <input type="file" class="d-none" id="fileInputer" multiple>
        </div>
      </div>
      <div class="col-4">
        <div class="row">
          <div class="col-12 pb-2">
            <div class="row justify-content-between">
              <div class="col-auto">■ 수신자</div>
              <div class="col-auto"><button type="button" class="btn btn-sm btn-info" id="addReadUserBtn">추가</button></div>
            </div>
          </div>
          <div class="col-1">no</div>
          <div class="col-9">수신자</div>
          <div class="col-2">삭제</div>
        </div>
        <hr class="my-1">
        <div class="row">
          <div class="col-12" id="readUserRow">
            <th:block th:each="readUser, idx:${sri.readUserList}">
              <div class="row my-1 readUserRow">
                <input type="hidden" class="userSeq" th:value="${readUser.userSeq}">
                <input type="hidden" class="ogCd" th:value="${readUser.ogCd}">
                <input type="hidden" class="ofcCd" th:value="${readUser.ofcCd}">
                <input type="hidden" class="titleCd" th:value="${readUser.titleCd}">
                <input type="hidden" class="userNm" th:value="${readUser.userNm}">
                <div class="col-1 rowSeq" th:text="${idx.index+1}"></div>
                <div class="col-9">
                  <th:block th:each="commonCode:${session.commonCode.get('OG')}">
                    <th:block th:if="${commonCode.itemCd eq readUser.ogCd}" th:text="${commonCode.itemValue}"></th:block>
                  </th:block>
                  <th:block th:each="commonCode:${session.commonCode.get('OFC')}">
                    <th:block th:if="${commonCode.itemCd eq readUser.ofcCd}" th:text="${commonCode.itemValue}"></th:block>
                  </th:block>
                  <!--<th:block th:each="commonCode:${session.commonCode.get('JT')}">
                    <th:block th:if="${commonCode.itemCd eq readUser.titleCd}" th:text="|${commonCode.itemValue} ${readUser.userNm}|"></th:block>
                  </th:block>-->
                  <th:block th:text="${readUser.userNm}"></th:block>
                </div>
                <div class="col-2">
                  <button type="button" class="btn btn-sm btn-outline-danger rowDeleteBtn"><i class="bi bi-x"></i></button>
                </div>
              </div>
            </th:block>
          </div>
        </div>
      </div>
    </div>
  </form>
</div>
<div class="modal-footer">
  <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">닫기</button>
  <button type="button" class="btn btn-warning" id="saveTempBtn">임시저장</button>
  <button type="button" class="btn btn-primary" id="saveSriBtn">저장</button>
</div>