<!DOCTYPE html>
<html lang="ko" xmlns:th="http://www.thymeleaf.org">
<div class="modal-header">
  <h5 class="modal-title" id="menuEditModalLabel">수정</h5>
  <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
  <form id="equipModifyForm" th:action="@{/equip/updateEquip}" method="post" enctype="multipart/form-data">
    <input type="hidden" name="_csrf_header" th:value="${_csrf.headerName}"/>
    <input type="hidden" th:name="${_csrf.parameterName}" th:value="${_csrf.token}"/>
    <input type="hidden" id="mEquKey" name="equKey" th:value="${equInfo.equKey}">
    <input type="hidden" name="versionNo" th:value="${equInfo.versionNo}">
    <div class="row mb-3">
      <label for="cat1Cd" class="col-sm-4 col-form-label col-form-label-sm text-center">관리처</label>
      <div class="col-sm-6">
        <select class="form-select form-select-sm" id="mMgtOrgan" name="mgtOrgan" th:disabled="${accessAuth ne 'ACC003'}">
                  <option value="">선택</option>
                  <th:block th:each="commonCode:${session.commonCode.get('OG')}">
                    <option th:value="${commonCode.itemCd}" th:text="${commonCode.itemValue}" th:selected="${commonCode.itemCd} == ${equInfo.mgtOrgan}"></option>
                  </th:block>
               </select>
      </div>
    </div>
    <div class="row mb-3">
      <label for="cat1Cd" class="col-sm-4 col-form-label col-form-label-sm text-center">분류</label>
      <div class="col-sm-6">
        <select class="form-select form-select-sm" id="equType" name="equType">
          <option value="">-분류 선택-</option>
           <th:block th:each="commonCode:${session.commonCode.get('IT')}">
             <option th:value="${commonCode.itemCd}" th:text="${commonCode.itemValue}" th:selected="${commonCode.itemCd} == ${equInfo.equType}"></option>
           </th:block>
        </select>
      </div>
    </div>
    <div class="row mb-3">
      <label for="cat2Cd" class="col-sm-4 col-form-label col-form-label-sm text-center">세부분류</label>
      <div class="col-sm-6">
        <select class="form-select form-select-sm" id="detailType" name="detailType">
        	 <option value="">-세부분류 선택-</option>
          <th:block th:each="commonCode:${session.commonCode.get(equInfo.equType)}">         	 
             <option th:value="${commonCode.itemCd}" th:text="${commonCode.itemValue}" th:selected="${commonCode.itemCd} == ${equInfo.detailType}"></option>
           </th:block>
        </select>
      </div>
    </div>
    <div class="row mb-3">
      <label for="cat3Cd" class="col-sm-4 col-form-label col-form-label-sm text-center">취득연도</label>
      <div class="col-sm-6">
        <input type="text" class="form-control mStoredYear" name="storedYear" th:value="${equInfo.storedYear}" readonly>
      </div>
    </div>
    <div class="row mb-3">
      <label for="cat3Cd" class="col-sm-4 col-form-label col-form-label-sm text-center">보유량</label>
      <div class="col-sm-6">
        <input type="number" class="form-control" id="mItemQty" name="itemQty" th:value="${equInfo.itemQty}" placeholder="수량 직접입력">
      </div>
    </div>
     <div class="row mb-3">
      <label for="cat2Cd" class="col-sm-4 col-form-label col-form-label-sm text-center">상태</label>
      <div class="col-sm-6">
        <select class="form-select form-select-sm" name="itemCondition">
          <option value="">상태 선택</option>
          <th:block th:each="commonCode:${session.commonCode.get('ITCON')}">
             <option th:value="${commonCode.itemCd}" th:text="${commonCode.itemValue}" th:selected="${commonCode.itemCd} == ${equInfo.itemCondition}"></option>
           </th:block>
        </select>
      </div>
    </div>
    <div class="row mb-3">
      <label for="cat3Cd" class="col-sm-4 col-form-label col-form-label-sm text-center">비고</label>
      <div class="col-sm-6">
        <input type="text" class="form-control" name="note" th:value="${equInfo.note}">
      </div>
    </div>
    <div class="row mb-3">
      <label for="cat3Cd" class="col-sm-4 col-form-label col-form-label-sm text-center">장비사진</label>
      <div class="col-sm-6">
      	<div id="imgUpload">
	        <input type="text" name="noUpdateImg" class="form-control" th:value="${equInfo.origNm}" readonly th:if="${not #strings.isEmpty(equInfo.origNm)}">
	        <input type="button" id="deleteImgBtn" value="삭제" th:if="${not #strings.isEmpty(equInfo.origNm)}" th:attr="onclick=|deleteImg('${equInfo.equKey}','${equInfo.versionNo}')|">
	        <input type="text" class="form-control" value="등록된 사진이 없습니다." readonly th:if="${#strings.isEmpty(equInfo.origNm)}">
	        <input type="button" id="addImgBtn" value="추가" th:if="${#strings.isEmpty(equInfo.origNm)}">
        </div>
      	<div id="imgUpdate" style="display:none">
        	<input type="file" class="form-control" name="file" accept="image/gif,image/jpeg,image/png">
        </div>
      </div>
    </div>
  </form>
</div>
<div class="modal-footer justify-content-between">
  <div class="col-auto">
    <button type="button" class="btn btn-secondary" id="closeModal" data-bs-dismiss="modal">닫기</button>
    <button type="button" class="btn btn-primary" id="updateEquip" th:if="${accessAuth eq 'ACC003'} or ${wrtId eq userId}">수정</button>
  	<button type="button" class="btn btn-danger" id="deleteEquip" th:if="${accessAuth eq 'ACC003'} or ${wrtId eq userId}">삭제</button>
  </div>
</div>
</html>