<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" isELIgnored="false" session="false"%>
<%@ include file="/WEB-INF/jsp/include/taglib.jsp"%>
              <form id="menu-form">
                <div class="row g-3">
                  <div class="col-md-12">
                    <div class="row">
                      <label class="col-sm-2 col-form-label text-sm-end" for="id"
                        >아이디</label
                      >
                      <div class="col-sm-10">
                        <input name="id" type="text" readonly maxlength="50" class="form-control" placeholder="저장하시면 시스템이 부여합니다." />
                        <input name="parentID" type="hidden" />
                      </div>
                    </div>
                  </div>
                  <div class="col-md-12">
                    <div class="row">
                      <label class="col-sm-2 col-form-label text-sm-end" for="name"
                        >이름</label
                      >
                      <div class="col-sm-10">
                        <input name="name" type="text" required maxlength="60" class="form-control" placeholder="메뉴 이름" />
                      </div>
                    </div>
                  </div>
                  <div class="col-md-12">
                    <div class="row"> 
                      <label class="col-sm-2 col-form-label text-sm-end" for="action"
                        >URL</label
                      > 
                      <div class="col-sm-10 input-group" style="width:83.3%;">
                        <span id="btnSelectURL" onClick="setURL();" class="input-group-text"><i class="bx bx-search"></i></span>
                        <input name="action" type="text" maxlength="60" class="form-control" placeholder="URL" />
                      </div> 
                    </div>
                  </div>
                  <div class="col-md-12">
                    <div class="row">
                      <label class="col-sm-2 col-form-label text-sm-end" for="description"
                        >설명</label
                      >
                      <div class="col-sm-10">
                        <input name="description" type="text" maxlength="200" class="form-control" placeholder="메뉴 설명"/>
                      </div>
                    </div>
                  </div>
                  <div class="col-md-12">
                    <div class="row">
                      <label class="col-sm-2 col-form-label text-sm-end" for="imageName"
                        >이미지 이름</label
                      >
                      <div class="col-sm-10">
                        <input name="imageName" type="text" maxlength="200" class="form-control" placeholder="이미지 이름"/>
                      </div>
                    </div>
                  </div>
                  <div class="col-md-12">
                    <div class="row">
                      <label class="col-sm-2 col-form-label text-sm-end" for="imageConf"
                        >이미지 설정</label
                      >
                      <div class="col-sm-10">
                        <input name="imageConf" type="text" maxlength="200" class="form-control" placeholder="이미지 설정"/>
                      </div>
                    </div>
                  </div>
                <div class="row mt-4 justify-content-end">
                      <div class="col-sm-12" style="text-align:right;">
                        <button id="btnSaveAuth" onclick="saveMenu();" type="button" class="btn btn-primary">저장</button>
                      </div>
                </div>
              </form>
<c:set var="menuFunc" scope="request">
var menuFields = new FormFields("#menu-form");

menuControl.setInfo = obj => {
	menuFields.set(obj);
	$("input[name='name']").focus();
}

menuControl.onModify = (changed) => {
	if (["name", "url"].filter(e => changed.includes(e)).length < 1)
		return;
}

async function setURL() {
	let url = await selectURL(false);
	$("input[name='action']").val(url).change();
}

function saveMenu() {
	if (!$("#menu-form input").validInputs()) return;
	
	dialog.alert({
		content:"현재 메뉴 정보를 저장하시겠습니까?",
		onOK:() => menuControl.save(menuFields.get())
	});
}

$("#menu-form input")
	.change(function() {
		let input = $(this),
 			name = input.attr("name"),
			val = input.val();
		menuControl.setValue(name, val);
	})
	.onEnterPress(() => saveMenu());
</c:set>