<!DOCTYPE html>
<html lang="ko" xmlns:th="http://www.thymeleaf.org">
<div class="modal-header">
  <h5 class="modal-title" id="resultEditModalLabel" th:text="${result.resultKey eq null?'청산보고서 작성':'청산보고서 수정'}"></h5>
  <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body" id="resultEditBody">
  <form action="#" method="post" id="resultEditForm">
    <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="resultKey" th:value="${result.resultKey}">
    <input type="hidden" name="wrtOrgan" th:value="${result.wrtOrgan}">
    <input type="hidden" name="wrtPart" th:value="${result.wrtPart}">
    <input type="hidden" name="wrtUserSeq" th:value="${result.wrtUserSeq}">
    <input type="hidden" name="resultState" id="resultState" th:value="${result.resultState}">
    <ul class="nav nav-tabs" id="userTab" role="tablist">
      <li class="nav-item" role="presentation">
        <button class="nav-link active" id="clearReportTab" data-bs-toggle="tab" data-bs-target="#clearReportTabPanel" type="button" role="tab" aria-controls="clearReportTabPanel" aria-selected="true">청산보고서</button>
      </li>
      <li class="nav-item" role="presentation">
        <button class="nav-link" id="resultReportTab" data-bs-toggle="tab" data-bs-target="#resultReportTabPanel" type="button" role="tab" aria-controls="resultReportTabPanel" aria-selected="false">결과보고서</button>
      </li>
      <li class="nav-item" role="presentation">
        <button class="nav-link" id="affairListTab" data-bs-toggle="tab" data-bs-target="#affairListTabPanel" type="button" role="tab" aria-controls="affairListTabPanel" aria-selected="false">견문목록&증빙자료</button>
      </li>
    </ul>
    <div class="tab-content border border-top-0" id="configInfo">
      <div class="tab-pane fade p-2 show active" id="clearReportTabPanel" role="tabpanel" aria-labelledby="clearReportTab" tabindex="0">
        <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="${result.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(result.wrtDt, 'yyyy-MM-dd HH:mm')}" readonly>
          </div>
        </div>
        <div class="mb-3 row">
          <label for="clearTitle" 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="clearTitle" name="clearTitle" th:value="${result.clearTitle}">
          </div>
        </div>
        <div class="mb-3 row">
          <label for="useDateSelectorDiv" class="col-sm-2 col-form-label col-form-label-sm text-center">사용기간</label>
          <div class="col-sm-4">
            <div class="input-group w-auto input-daterange" id="useDateSelectorDiv">
              <input type="text" class="form-control form-control-sm" id="useStartDt" name="useStartDt" th:value="${#temporals.format(result.useStartDt, 'yyyy-MM-dd')}" readonly>
              <input type="text" class="form-control form-control-sm" id="useEndDt" name="useEndDt" th:value="${#temporals.format(result.useEndDt, 'yyyy-MM-dd')}" readonly>
            </div>
          </div>
          <label for="workDateSelectorDiv" class="col-sm-2 col-form-label col-form-label-sm text-center">사업기간</label>
          <div class="col-sm-4">
            <div class="input-group w-auto input-daterange" id="workDateSelectorDiv">
              <input type="text" class="form-control form-control-sm" id="workStartDt" name="workStartDt" th:value="${#temporals.format(result.workStartDt, 'yyyy-MM-dd')}" readonly>
              <input type="text" class="form-control form-control-sm" id="workEndDt" name="workEndDt" th:value="${#temporals.format(result.workEndDt, 'yyyy-MM-dd')}" readonly>
            </div>
          </div>
        </div>
        <div class="mb-3 row">
          <label for="planPrice" class="col-sm-2 col-form-label col-form-label-sm text-center">계획금액</label>
          <div class="col-sm-4">
            <div class="row">
              <div class="col-auto me-0">
                <input type="text" class="form-control form-control-sm" id="planPrice" name="planPrice" th:value="${#numbers.formatInteger(result.planPrice, 1)}">
              </div>
              <label for="planPrice" class="col-sm-auto col-form-label col-form-label-sm">원</label>
            </div>
          </div>
          <label for="usePrice" class="col-sm-2 col-form-label col-form-label-sm text-center">집행액</label>
          <div class="col-sm-4">
            <div class="row">
              <div class="col-auto me-0">
                <input type="text" class="form-control form-control-sm" id="usePrice" name="usePrice" th:value="${#numbers.formatInteger(result.usePrice, 1)}">
              </div>
              <label for="usePrice" class="col-sm-auto col-form-label col-form-label-sm">원</label>
            </div>
          </div>
        </div>
        <div class="mb-3 row justify-content-center">
          <label for="clearInfoAddBtn" class="col-sm-2 col-form-label col-form-label-sm text-center">세부<br>집행내역</label>
          <div class="col-sm-10">
            <div class="row">
              <div class="col-1">no</div>
              <div class="col-3">구분</div>
              <div class="col-3">상세</div>
              <div class="col-5">금액</div>
            </div>
            <hr class="my-1">
            <div class="row">
              <div class="col-12" id="clearInfoRow">
                <th:block th:each="readUser, idx:${faRpt.readUserList}">
                  <div class="row my-1 readUserRow" th:id="|row${idx.index}|">
                    <input type="hidden" class="userSeq" th:name="${#strings.concat('readUserList[', idx.index,'].userSeq')}" th:value="${readUser.userSeq}">
                    <input type="hidden" class="ogCd" th:name="${#strings.concat('readUserList[', idx.index,'].ogCd')}" th:value="${readUser.ogCd}">
                    <input type="hidden" class="ofcCd" th:name="${#strings.concat('readUserList[', idx.index,'].ofcCd')}" th:value="${readUser.ofcCd}">
                    <input type="hidden" class="titleCd" th:name="${#strings.concat('readUserList[', idx.index,'].titleCd')}" th:value="${readUser.titleCd}">
                    <input type="hidden" class="userNm" th:name="${#strings.concat('readUserList[', idx.index,'].userNm')}" th:value="${readUser.usernm}">
                    <div class="col-1 rowSeq" th:text="${idx.count}"></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>
                    </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 class="row justify-content-center">
              <div class="col-auto">
                <button type="button" class="btn btn-sm btn-outline-primary" id="clearInfoAddBtn"><i class="bi bi-plus-lg"></i></button>
              </div>
            </div>
          </div>
        </div>
        <!--<div class="mb-3 row">
          <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(result.fileList)}">
                <br>파일을 업로드 해주세요.
              </th:block>
              <th:block th:unless="${#arrays.isEmpty(result.fileList)}">
                <div class='row-col-6' th:each="resultFile:${result.fileList}">
                  <span th:data-fileseq="${resultFile.fileSeq}" th:text="|${resultFile.origNm}.${resultFile.fileExtn} ${resultFile.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 class="mb-3 row">
          <label for="clearEtc" 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="clearEtc" name="clearEtc" th:value="${result.clearEtc}">
          </div>
        </div>
      </div>
      <div class="tab-pane fade p-2" id="resultReportTabPanel" role="tabpanel" aria-labelledby="resultReportTab" tabindex="0">
        <div class="mb-3 row">
          <label for="resultTitle" 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="resultTitle" name="resultTitle" th:value="${result.clearTitle}">
          </div>
        </div>
        <div class="mb-3 row">
          <label class="col-sm-2 col-form-label col-form-label-sm text-center">활동기간</label>
          <div class="col-sm-4">
            <div class="input-group w-auto">
              <input type="text" class="form-control form-control-sm workStartDtCopy" th:value="${#temporals.format(result.workStartDt, 'yyyy-MM-dd')}" readonly>
              <input type="text" class="form-control form-control-sm workEndDtCopy" th:value="${#temporals.format(result.workEndDt, 'yyyy-MM-dd')}" readonly>
            </div>
          </div>
          <label for="usePriceCopy" class="col-sm-2 col-form-label col-form-label-sm text-center">집행액</label>
          <div class="col-sm-4">
            <div class="row">
              <div class="col-auto me-0">
                <input type="text" class="form-control form-control-sm" id="usePriceCopy" th:value="${result.usePrice}" readonly>
              </div>
              <label for="usePriceCopy" class="col-sm-auto col-form-label col-form-label-sm">원</label>
            </div>
          </div>
        </div>
        <div class="mb-3 row justify-content-center">
          <label for="resultInfoRow" class="col-sm-2 col-form-label col-form-label-sm text-center">활동내용</label>
          <div class="col-sm-10">
            <div class="row">
              <div class="col-1">no</div>
              <div class="col-3">접촉 대상자</div>
              <div class="col-7">접촉 내용</div>
              <div class="col-1"></div>
            </div>
            <hr class="my-1">
            <div class="row">
              <div class="col-12" id="resultInfoRow">
                <th:block th:each="info:${result.resultInfoList}">
                  <div class="row my-1 infoRow" th:id="|row${info.infoSeq}|">
                    <input type="hidden" class="infoSeq resultInfoSeq" th:name="${#strings.concat('resultInfoList[', info.infoSeq,'].infoSeq')}" th:value="${info.infoSeq}">
                    <div class="col-1 infoSeq" th:text="${info.infoSeq+1}"></div>
                    <div class="col-3">
                      <input type="text" class="form-control form-control-sm" th:name="${#strings.concat('resultInfoList[', info.infoSeq,'].contactTarget')}"
                             th:value="${info.contactTarget}">
                    </div>
                    <div class="col-7">
                      <textarea class="contactInfo" th:id="|contactInfo${info.infoSeq}|" th:name="${#strings.concat('resultInfoList[', info.infoSeq,'].contactInfo')}"
                                th:utext="${info.contactInfo}"></textarea>
                    </div>
                    <div class="col-1">
                      <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 class="row justify-content-center">
              <div class="col-auto">
                <button type="button" class="btn btn-sm btn-outline-primary" id="resultInfoAddBtn"><i class="bi bi-plus-lg"></i></button>
              </div>
            </div>
          </div>
        </div>
        <!--<div class="mb-3 row">
          <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(result.fileList)}">
                <br>파일을 업로드 해주세요.
              </th:block>
              <th:block th:unless="${#arrays.isEmpty(result.fileList)}">
                <div class='row-col-6' th:each="resultFile:${result.fileList}">
                  <span th:data-fileseq="${resultFile.fileSeq}" th:text="|${resultFile.origNm}.${resultFile.fileExtn} ${resultFile.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 class="mb-3 row">
          <label for="resultEtc" 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="resultEtc" name="resultEtc" th:value="${result.clearEtc}">
          </div>
        </div>
      </div>
      <div class="tab-pane fade p-2" id="affairListTabPanel" role="tabpanel" aria-labelledby="affairListTab" tabindex="0">
        <div class="mb-3 row">
          <label class="col-sm-2 col-form-label col-form-label-sm text-center">활동기간</label>
          <div class="col-sm-4">
            <div class="input-group w-auto">
              <input type="text" class="form-control form-control-sm workStartDtCopy" th:value="${#temporals.format(result.workStartDt, 'yyyy-MM-dd')}" readonly>
              <input type="text" class="form-control form-control-sm workEndDtCopy" th:value="${#temporals.format(result.workEndDt, 'yyyy-MM-dd')}" readonly>
            </div>
          </div>
          <div class="col-auto">
            <input type="button" class="btn btn-sm btn-outline-primary" id="affairModalBtn" value="불러오기">
          </div>
        </div>
        <div class="mb-3 row justify-content-center">
          <div class="col-11" id="affairListDiv">
            <table class="table table-hover">
              <thead>
              <tr>
                <th>작성일자</th>
                <th>제목</th>
                <th>활용</th>
              </tr>
              </thead>
              <tbody id="affairListTbody">
              <tr class="affairViewTr" th:each="affair:${result.affairBoardList}">
                <input type="hidden" class="affairKey" th:value="${affair.affairKey}">
                <td th:text="${#temporals.format(affair.wrtDt, 'yyyy-MM-dd')}"></td>
                <td th:text="${affair.title}"></td>
                <th:block th:each="ratingCode:${session.commonCode.get('AAR')}">
                  <td class="affairRate" th:if="${ratingCode.itemCd eq affair.affairRate}" th:text="${#strings.concat(ratingCode.itemValue, (affair.organUp eq 'T'?'(상보)':''))}"></td>
                </th:block>
              </tr>
              </tbody>
            </table>
          </div>
        </div>
        <div class="mb-3 row">
          <label for="fileInputer" class="col-sm-2 col-form-label col-form-label-sm text-center">증빙자료</label>
          <div class="col-sm-9" style="min-height: 70px;">
            <div class="w-100 h-100 border border-info rounded text-center" id="uploadDiv">
              <th:block th:if="${#arrays.isEmpty(result.fileList)}">
                <br>파일을 업로드 해주세요.
              </th:block>
              <th:block th:unless="${#arrays.isEmpty(result.fileList)}">
                <div class='row-col-6' th:each="resultFile:${result.fileList}">
                  <span th:data-fileseq="${resultFile.fileSeq}" th:text="|${resultFile.origNm}.${resultFile.fileExtn} ${resultFile.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>
  </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="saveResultBtn">저장</button>
</div>