<!DOCTYPE html>
<html lang="ko" xmlns:th="http://www.thymeleaf.org">
  <div class="modal-header">
    <th:block th:if="${boardInvestigation.ivsgtKey eq null}">
      <th:block th:if="${boardInvestigation.ivsgtType eq 'arrest'}">
        <h5 class="modal-title" id="planEditModalLabel">검거보고서 작성</h5>
      </th:block>
      <th:block th:if="${boardInvestigation.ivsgtType eq 'proceeding'}">
        <h5 class="modal-title" id="planEditModalLabel">진행보고서 작성</h5>
      </th:block>
      <th:block th:if="${boardInvestigation.ivsgtType eq 'result'}">
        <h5 class="modal-title" id="planEditModalLabel">결과보고서 작성</h5>
      </th:block>
    </th:block>
    <th:block th:if="${boardInvestigation.ivsgtKey != null}">
      <th:block th:if="${boardInvestigation.ivsgtType eq 'arrest'}">
        <h5 class="modal-title" id="planEditModalLabel">검거보고서 수정</h5>
      </th:block>
      <th:block th:if="${boardInvestigation.ivsgtType eq 'proceeding'}">
        <h5 class="modal-title" id="planEditModalLabel">진행보고서 수정</h5>
      </th:block>
      <th:block th:if="${boardInvestigation.ivsgtType eq 'result'}">
        <h5 class="modal-title" id="planEditModalLabel">결과보고서 수정</h5>
      </th:block>
    </th:block>
    <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
  </div>
  <div class="modal-body" id="ivsgtEditBody">
    <form action="#" method="post" id="ivsgtEditForm">
      <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="ivsgtKey" th:value="${boardInvestigation.ivsgtKey}">
      <input type="hidden" name="wrtOrgan" th:value="${boardInvestigation.wrtOrgan}">
      <input type="hidden" id="contentStatus" name="contentStatus">
      <input type="hidden" name="ivsgtType" th:value="${boardInvestigation.ivsgtType}">
      <input type="hidden" name="arrestTypeKey" th:value="${boardInvestigation.arrestType != null ? boardInvestigation.arrestType.arrestTypeKey: ''}">
      <div class="mb-3 row">
        <label for="wrtNm" class="col-sm-2 col-form-label text-center">작성자</label>
        <div class="col-sm-2">
          <input type="text" class="form-control" id="wrtNm" name="wrtNm" th:value="${boardInvestigation.wrtNm}" readonly>
        </div>
        <label for="wrtDt" class="col-sm-2 col-form-label text-center">작성일시</label>
        <div class="col-sm-2">
          <input type="text" class="form-control" id="wrtDt" name="wrtDt" th:value="${#temporals.format(boardInvestigation.wrtDt, 'yyyy-MM-dd HH:mm')}" readonly>
        </div>
      </div>
      <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" id="contentTitle" name="contentTitle" th:value="${boardInvestigation.contentTitle}">
        </div>
      </div>
      <div class="mb-3 row" id="arrestTypeDiv">
        <label class="col-sm-2 col-form-label text-center">검거유형1</label>
        <div class="col-sm-2">
          <select class="form-select form-select-sm" name="arrestCd" id="arrestCd">
            <option value="">검거유형1 선택-</option>
            <th:block th:each="commonCode:${session.commonCode.get('AT')}">
                <option th:value="${commonCode.itemCd}" th:text="${commonCode.itemValue}"
                        th:selected="${boardInvestigation.arrestType != null and commonCode.itemCd eq boardInvestigation.arrestType.arrestCd}"></option>
            </th:block>
          </select>
        </div>
        <label class="col-sm-2 col-form-label text-center">검거유형2</label>
        <div class="col-sm-2">
          <select class="form-select form-select-sm" name="arrestCd2" id="arrestCd2">
            <option value="">검거유형2 선택-</option>
            <th:block th:each="num : ${#numbers.sequence(1,#lists.size(session.commonCode.get('AT')))}">
              <th:block th:if="${boardInvestigation.arrestType ne null && 'AT'+num == boardInvestigation.arrestType.arrestCd}" th:each="commonCode:${session.commonCode.get('AT'+num)}">
                <option th:value="${commonCode.itemCd}" th:text="${commonCode.itemValue}" th:selected="${boardInvestigation.arrestType.arrestCd2 eq commonCode.itemCd}"></option>
              </th:block>
            </th:block>
          </select>
        </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="${boardInvestigation.hashTags}"
                 placeholder="띄어쓰기로 각 태그를 구분합니다. 한 태그 내에서는 띄어쓰기 없이 입력해주세요. ex)태그1 태그2">
        </div>
      </div>
      <div class="mb-3 row justify-content-center">
        <label for="contentInfoDiv" class="col-sm-2 col-form-label text-center">사건개요</label>
        <div class="col-sm-10" id="contentInfoDiv">
          <textarea type='text' name='contentInfo' th:utext="${boardInvestigation.contentInfo}"></textarea>
        </div>
        <div class="mb-3 row justify-content-center">
          <label for="contentMainDiv" class="col-sm-2 col-form-label text-center">주요내용</label>
          <div class="col-sm-10" id="contentMainDiv">
              <textarea type='text' name='contentMain' th:utext="${boardInvestigation.contentMain}"></textarea>
          </div>
        </div>
        <div class="row mb-3">
          <label for="fileInputer" class="col-sm-2 col-form-label 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(boardInvestigation.fileList)}">
                <br>파일을 업로드 해주세요.
              </th:block>
              <th:block th:unless="${#arrays.isEmpty(boardInvestigation.fileList)}">
                <div class='row-col-6' th:each="ivsgtFile:${boardInvestigation.fileList}">
                  <span th:data-fileseq="${ivsgtFile.fileSeq}" th:text="|${ivsgtFile.origNm}.${ivsgtFile.fileExtn} ${ivsgtFile.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>
        <th:block th:if="${boardInvestigation.ivsgtType eq 'proceeding' or boardInvestigation.ivsgtType eq 'result'}">
          <div class="row mb-3">
            <label for="relatedReportDiv" class="col-sm-2 col-form-label text-center">연관보고서</label>
            <div class="col-sm-10" id="relatedReportDiv">
              <div class="row justify-content-start">
                <div class="col-4">
                  <input type="text" class="form-control form-control-sm" placeholder="" name="searchTitle">
                </div>
                <input type="button" class="btn btn-sm btn-primary col-auto" id="relatedReportSearchBtn" value="검색">
                <div class="col-auto">
                  <input type="checkbox" id="relatedReport" th:checked="${#lists.isEmpty(boardInvestigation.relatedReportsList)}">
                  <label for="relatedReport">연관보고서 없음</label>
                </div>
              </div>
            </div>
          </div>
          <div class="row mb-3">
            <label for="relatedReportDiv" class="col-sm-2 col-form-label text-center"></label>
            <div class="col-sm-10 mb-3 row" id="relatedReportSearchDiv">
              <th:block th:each="relatedReports:${boardInvestigation.relatedReportsList}">
                <div class="col-auto">
                  <input type="hidden" name="relatedReportsKeyList" th:value="${relatedReports.relatedReportsKey}">
                  <input type="hidden" name="childIvsgtKeyList" th:value="${relatedReports.childIvsgtKey}">
                  <input class="border-0" type="text" name="relatedReportsText" th:value="${relatedReports.contentTitle}" readonly>
                  <button class="btn btn-sm btn-primary col-auto cancel-btn">X</button>
                </div>
              </th:block>
            </div>
          </div>

          <div class="modal fade" id="searchViewModal" data-bs-backdrop="static" data-bs-keyboard="false" tabindex="-1" aria-labelledby="searchViewModalLabel" aria-hidden="true" style="background-color: var(--bs-border-color-translucent);">
            <div class="modal-dialog modal-s modal-dialog-scrollable">
              <div class="modal-content" id="searchViewBody">

              </div>
            </div>
          </div>
        </th:block>
      </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="saveIvsgtBtn">저장</button>
  </div>
</html>