/*!
 * KoliBri - The accessible HTML-Standard
 */
import{m as KolFormTag}from"./component-names-0a8a1a6c.js";import{q as setEventTarget,K as KoliBriDevHelper,j as devHint}from"./prop.validators-5a58fa40.js";import{a as getExperimentalMode,L as Log}from"./dev.utils-fab45cbc.js";const searchFormElement=e=>{for(getExperimentalMode()&&(devHint("↓ Search form element start."),Log.debug(e));e instanceof HTMLElement&&"FORM"!==e.tagName&&e.tagName!==KolFormTag.toUpperCase();){try{e=e.parentElement instanceof HTMLElement?e.parentElement:e.parentNode instanceof ShadowRoot?e.parentNode.host:null}catch(e){}getExperimentalMode()&&(Log.debug(e),devHint("↑ Search form element finished."))}return e},propagateResetEventToForm=(e={})=>{var t,o;const a=searchFormElement(e.form);if(a instanceof HTMLElement){const e=new Event("reset",{bubbles:!0,cancelable:!0});if("FORM"===a.tagName)setEventTarget(e,a),a.dispatchEvent(e);else if(a.tagName===KolFormTag.toUpperCase()){setEventTarget(e,KoliBriDevHelper.querySelector("form",a));const n=a;"function"==typeof(null===(t=n._on)||void 0===t?void 0:t.onReset)&&(null===(o=n._on)||void 0===o||o.onReset(e))}}},propagateSubmitEventToForm=(e={})=>{const t=searchFormElement(e.form);if(t instanceof HTMLElement){const e=new SubmitEvent("submit",{bubbles:!0,cancelable:!0,submitter:t});if("FORM"===t.tagName)getExperimentalMode()&&!1===t.noValidate&&devHint("If you have not focusable or hidden form fields in your form, you should enable noValidate for your form.",{force:!0}),setTimeout((()=>{"function"==typeof t.requestSubmit?t.requestSubmit():(setEventTarget(e,t),t.dispatchEvent(e))}));else if(t.tagName===KolFormTag.toUpperCase()){setEventTarget(e,KoliBriDevHelper.querySelector("form",t));const o=t;setTimeout((()=>{var t,a;"function"==typeof(null===(t=o._on)||void 0===t?void 0:t.onSubmit)&&(null===(a=o._on)||void 0===a||a.onSubmit(e))}))}}};export{propagateResetEventToForm as a,propagateSubmitEventToForm as p};