<!DOCTYPE html>
<html lang="ko" xmlns:th="http://www.thymeleaf.org">
<div class="modal-header">
  <h5 class="modal-title" id="affairEditModalLabel" th:text="${affair.affairKey eq null?'견문 작성':'견문 수정'}"></h5>
  <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body" id="affairEditBody">
  <form action="#" method="post" id="affairEditForm">
    <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="affairKey" th:value="${affair.affairKey}">
    <input type="hidden" name="wrtOrgan" th:value="${affair.wrtOrgan}">
    <input type="hidden" name="wrtPart" th:value="${affair.wrtPart}">
    <input type="hidden" name="wrtUserSeq" th:value="${affair.wrtUserSeq}">
    <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" 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" id="wrtDt" name="wrtDt" th:value="${#temporals.format(affair.wrtDt, 'yyyy-MM-dd HH:mm')}" readonly>
      </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" 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" id="autoDelete" name="autoDelete" th:value="${affair.autoDelete}" readonly>
      </div>
      <label for="viewStatus" class="col-sm-1 col-form-label col-form-label-sm text-center">공개여부</label>
      <div class="col-sm-2">
        <select class="form-select form-select-sm" id="viewStatus" name="viewStatus">
          <option value="">선택</option>
          <th:block th:each="code:${session.commonCode.get('AVS')}">
            <option th:value="${code.itemCd}" th:text="${code.itemValue}" th:selected="${code.itemCd eq affair.viewStatus}"></option>
          </th:block>
        </select>
      </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">
        <select class="form-select form-select-sm" id="affairType1" name="affairType1">
          <option value="">선택</option>
          <th:block th:each="code:${session.commonCode.get('DC01')}">
            <option th:value="${code.itemCd}" th:text="${code.itemValue}" th:selected="${code.itemCd eq affair.affairType1}"></option>
          </th:block>
        </select>
      </div>
      <label for="affairType2" class="col-sm-1 col-form-label col-form-label-sm text-center">분야2</label>
      <div class="col-sm-2">
        <select class="form-select form-select-sm" id="affairType2" name="affairType2">
          <option value="">선택</option>
          <th:block th:each="code:${session.commonCode.get('DC02')}">
            <option th:value="${code.itemCd}" th:text="${code.itemValue}" th:selected="${code.itemCd eq affair.affairType2}"></option>
          </th:block>
        </select>
      </div>
      <label for="affairType3" class="col-sm-1 col-form-label col-form-label-sm text-center">분야3</label>
      <div class="col-sm-2">
        <select class="form-select form-select-sm" id="affairType3" name="affairType3">
          <option value="">선택</option>
          <th:block th:each="code:${session.commonCode.get('DC03')}">
            <option th:value="${code.itemCd}" th:text="${code.itemValue}" th:selected="${code.itemCd eq affair.affairType3}"></option>
          </th:block>
        </select>
      </div>
      <label for="affairType4" class="col-sm-1 col-form-label col-form-label-sm text-center">분야4</label>
      <div class="col-sm-2">
        <select class="form-select form-select-sm" id="affairType4" name="affairType4">
          <option value="">선택</option>
          <th:block th:each="code:${session.commonCode.get('DC04')}">
            <option th:value="${code.itemCd}" th:text="${code.itemValue}" th:selected="${code.itemCd eq affair.affairType4}"></option>
          </th:block>
        </select>
      </div>
    </div>
    <div class="mb-3 row">
      <label for="title" class="col-sm-1 col-form-label col-form-label-sm text-center">제목</label>
      <div class="col-sm-11">
        <input type="text" class="form-control form-control-sm" id="title" name="title" th:value="${affair.title}">
      </div>
    </div>
    <div class="mb-3 row">
      <label for="title" class="col-sm-1 col-form-label col-form-label-sm text-center">내용</label>
      <div class="col-sm-11">
        <textarea id="content" name="content" th:utext="${affair.content}"></textarea>
      </div>
    </div>
    <div class="mb-3 row">
      <label for="hashTags" class="col-sm-1 col-form-label col-form-label-sm text-center">해시태그</label>
      <div class="col-sm-11">
        <input type="text" class="form-control form-control-sm" id="hashTags" name="hashTags" th:value="${affair.hashTags}"
               placeholder="띄어쓰기로 각 태그를 구분합니다. 한 태그 내에서는 띄어쓰기 없이 입력해주세요. ex)태그1 태그2">
      </div>
    </div>
    <div class="mb-3 row">
      <label for="etc" class="col-sm-1 col-form-label col-form-label-sm text-center">비고</label>
      <div class="col-sm-11">
        <input type="text" class="form-control form-control-sm" id="etc" name="etc" th:value="${affair.title}">
      </div>
    </div>
    <div class="row mb-3">
      <label for="fileInputer" class="col-sm-1 col-form-label col-form-label-sm text-center">업로드<br>자료</label>
      <div class="col-sm-11" style="min-height: 70px;">
        <div class="w-100 h-100 border border-info rounded text-center" id="uploadDiv">
          <th:block th:if="${#arrays.isEmpty(affair.fileList)}">
            <br>파일을 업로드 해주세요.
          </th:block>
          <th:block th:unless="${#arrays.isEmpty(affair.fileList)}">
            <div class='row-col-6' th:each="affairFile:${affair.fileList}">
              <span th:data-fileseq="${affairFile.fileSeq}" th:text="|${affairFile.origNm}.${affairFile.fileExtn} ${affairFile.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>
  </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="saveAffairBtn">저장</button>
</div>