const AUTOFORM_BLUEPRINT=globalThis.Util.makeDom('\n
\n'),AUTOFORM_STYLE=globalThis.Util.makeDom("");globalThis.Component.register("AutoForm",t=>{t.state.schema||(t.state.schema=[]);const e=e=>{const i=(n=e||{})&&"object"==typeof n&&!n.__isProxy?globalThis.NewState(n):n;var n;t.data=i,t.state.data!==i&&(t.state.data=i)};t.state.__watch("data",e),e(t.state.data),t.vertical=t.hasAttribute("vertical"),t.horizontal=t.hasAttribute("horizontal"),t.inline=t.hasAttribute("inline"),t.nobutton=t.hasAttribute("nobutton"),t.submitlabel=t.getAttribute("submitlabel")||"",t.request={method:"POST"},t.response={},t.result=null,t.form=globalThis.$(t,"form"),t.submit=(e={})=>{if(!t.form.reportValidity())return globalThis.Toast?.show("{#verify failed#}",{type:"danger"});if(!t.dispatchEvent(new CustomEvent("submit",{detail:t.data,cancelable:!0,bubbles:!1})))return;const i={...t.request,data:t.data,noui:!0,...e};let n=null;if(t.api)n=t.api.do(i);else{if(!t.request.url)return console.warn("{#please config .api or .request.url to auto submit#}");n=globalThis.HTTP.request(i)}n.then(e=>{if(t.response=e,t.result=e.result,"object"==typeof e.result&&e.result.error)throw new Error(e.result.error);t.dispatchEvent(new CustomEvent("response",{detail:e,bubbles:!1}))}).catch(e=>{globalThis.Toast?.show(e.message,{type:"danger"}),t.dispatchEvent(new CustomEvent("error",{detail:e,bubbles:!0}))})}},AUTOFORM_BLUEPRINT,AUTOFORM_STYLE);const findAnchorInBlueprint=t=>{let e=t.querySelector("[control-wrapper]");if(e)return e;for(const i of t.querySelectorAll("template"))if(e=findAnchorInBlueprint(i.content),e)return e;return null},AutoForm={customTypes:[],register:(t,e)=>{const i=e||t;AutoForm.customTypes.find(e=>e.name===t)||(AutoForm.customTypes.push({name:t,typeName:i}),AutoForm._addAutoFormComponent(t,i))},_addAutoFormComponent:(t,e)=>{const i=findAnchorInBlueprint(AUTOFORM_BLUEPRINT);if(i){const n=globalThis.Util.makeDom(`<${t} $name="item.name" $.="item.setting || {}" $bind="thisNode.closest('AutoForm').data[item.name]" class="w-100">${t}>`);i.appendChild(n)}}};globalThis.AutoForm=AutoForm;