<!DOCTYPE html>
<html lang="ko" xmlns:th="http://www.thymeleaf.org">
<div class="modal-header">
  <h5 class="modal-title" id="faRptEditModalLabel" th:text="${faRpt.faRptKey eq null?'외사정보보고 작성':'외사정보보고 수정'}"></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="faRptEditForm">
    <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="faRptKey" th:value="${faRpt.faRptKey}">
    <input type="hidden" name="wrtOrgan" th:value="${faRpt.wrtOrgan}">
    <input type="hidden" name="wrtPart" th:value="${faRpt.wrtPart}">
    <input type="hidden" name="wrtUserSeq" th:value="${faRpt.wrtUserSeq}">
    <input type="hidden" name="wrtUserGrd" th:value="${faRpt.wrtUserGrd}">
    <input type="hidden" name="status" id="status" th:value="${faRpt.status}">
    <input type="hidden" name="refKey" th:value="${faRpt.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="${faRpt.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(faRpt.wrtDt, 'yyyy-MM-dd HH:mm')}" readonly>
          </div>
        </div>
        <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="faRptType" name="faRptType">
              <option value="">선택해주세요.</option>
              <th:block th:each="frCategory:${frCategoryList}">
                <option th:value="${frCategory.itemCd}" th:text="${frCategory.itemValue}" th:selected="${frCategory.itemCd eq faRpt.faRptType}"></option>
              </th:block>
            </select>
          </div>
        </div>
        <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">
            <input type="text" class="form-control form-control-sm" id="title" name="title" th:value="${faRpt.title}">
          </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">
            <textarea type='text' id="content" name='content' th:utext="${faRpt.content}"></textarea>
          </div>
        </div>
        <div class="mb-3 row">
          <label for="hashTags" class="col-sm-2 col-form-label col-form-label-sm text-center">해시태그</label>
          <div class="col-sm-10">
            <input type="text" class="form-control form-control-sm" id="hashTags" name="hashTags" th:value="${faRpt.hashTags}"
                   placeholder="띄어쓰기로 각 태그를 구분합니다. 한 태그 내에서는 띄어쓰기 없이 입력해주세요. ex)태그1 태그2">
          </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(faRpt.fileList)}">
                <br>파일을 업로드 해주세요.
              </th:block>
              <th:block th:unless="${#arrays.isEmpty(faRpt.fileList)}">
                <div class='row-col-6' th:each="faRptFile:${faRpt.fileList}">
                  <span th:data-fileseq="${faRptFile.fileSeq}" th:text="|${faRptFile.origNm}.${faRptFile.fileExtn} ${faRptFile.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:${faRpt.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="saveFaRptBtn">저장</button>
</div>