/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.24/esri/copyright.txt for details.
*/
define(["exports","./dom","./componentsUtils"],(function(e,t,n){"use strict";
/*!
   * All material copyright ESRI, All Rights Reserved, unless otherwise specified.
   * See https://github.com/Esri/calcite-components/blob/master/LICENSE.md for details.
   * v1.0.0-beta.82
   */const o="hidden-form-input";function r(e){return"checked"in e}const l=new WeakMap,a=new WeakSet;function c(e,t){const n="calciteInternalFormComponentRegister";let o=!1;return e.addEventListener(n,(e=>{o=e.composedPath().some((e=>a.has(e))),e.stopPropagation()}),{once:!0}),t.dispatchEvent(new CustomEvent(n,{bubbles:!0,composed:!0})),o}function u(e){var t;null===(t=e.formEl)||void 0===t||t.requestSubmit()}function d(e){var t;null===(t=e.formEl)||void 0===t||t.reset()}function s(e){const{el:n,value:o}=e,u=t.closestElementCrossShadowBoundary(n,"form");if(!u||c(u,n))return;e.formEl=u,e.defaultValue=o,r(e)&&(e.defaultChecked=e.checked);const d=(e.onFormReset||i).bind(e);u.addEventListener("reset",d),l.set(e.el,d),a.add(n)}function i(){r(this)?this.checked=this.defaultChecked:this.value=this.defaultValue}function f(e){const{el:t,formEl:n}=e;if(!n)return;const o=l.get(t);n.removeEventListener("reset",o),l.delete(t),e.formEl=null,a.delete(t)}function m(e,t){e.defaultValue=t}function h(e){const{el:t,formEl:n,name:r,value:l}=e,{ownerDocument:a}=t,c=t.querySelectorAll(`input[slot="${o}"]`);if(!n||!r)return void c.forEach((e=>e.remove()));const u=Array.isArray(l)?l:[l],d=[],s=new Set;let i;c.forEach((t=>{const n=u.find((e=>e==t.value));null!=n?(s.add(n),p(e,t,n)):d.push(t)})),u.forEach((t=>{if(s.has(t))return;let n=d.pop();n||(n=a.createElement("input"),n.slot=o),i||(i=a.createDocumentFragment()),i.append(n),p(e,n,t)})),i&&t.append(i),d.forEach((e=>e.remove()))}function p(e,t,n){var o;const{defaultValue:l,disabled:a,name:c,required:u}=e;t.defaultValue=l,t.disabled=a,t.name=c,t.required=u,t.tabIndex=-1,r(e)?(t.defaultChecked=e.defaultChecked,t.value=e.checked?n||"on":"",a||e.checked||(t.disabled=!0)):t.value=n||"",null===(o=e.syncHiddenFormInput)||void 0===o||o.call(e,t)}const v=({component:e})=>(h(e),n.h("slot",{name:o}));e.HiddenFormInputSlot=v,e.afterConnectDefaultValueSet=m,e.connectForm=s,e.disconnectForm=f,e.resetForm=d,e.submitForm=u}));
