/*!
 * KoliBri - The accessible HTML-Standard
 */
import{proxyCustomElement,HTMLElement,h,Host}from"@stencil/core/internal/client";import{n as watchBoolean,P as watchString,a0 as validateErrorList}from"./index2.js";import{t as translate}from"./i18n2.js";import{k as KolAlertTag,h as KolLinkTag,j as KolIndentedTextTag}from"./component-names.js";const KolForm$1=proxyCustomElement(class extends HTMLElement{constructor(){super(),this.__registerHost(),this.__attachShadow(),this.onSubmit=t=>{var e,o;t.preventDefault(),t.stopPropagation(),"function"==typeof(null===(e=this.state._on)||void 0===e?void 0:e.onSubmit)&&(null===(o=this.state._on)||void 0===o||o.onSubmit(t))},this.onReset=t=>{var e,o;t.preventDefault(),t.stopPropagation(),"function"==typeof(null===(e=this.state._on)||void 0===e?void 0:e.onReset)&&(null===(o=this.state._on)||void 0===o||o.onReset(t))},this.handleLinkClick=t=>{var e;const o=null===(e=t.target)||void 0===e?void 0:e.href;if(o){const t=new URL(o),e=document.querySelector(t.hash);e&&"function"==typeof e.focus&&(e.scrollIntoView({behavior:"smooth"}),e.focus())}},this._on=void 0,this._requiredText=!0,this._errorList=void 0,this.state={}}render(){return h(Host,{key:"65d715836bb74ba26265a82596c68938518f1bd6",class:"kol-form"},this._errorList&&this._errorList.length>0&&h(KolAlertTag,{_type:"error"},translate("kol-error-list-message"),h("nav",{"aria-label":translate("kol-error-list")},h("ul",null,this._errorList.map(((t,e)=>h("li",{key:e},h(KolLinkTag,{_href:t.selector,_label:t.message,_on:{onClick:this.handleLinkClick},ref:t=>{0===e&&(this.errorListElement=t)}}))))))),h("form",{key:"47ab1f7b0e6ab78c81d63e073b9cde8baf007f39",method:"post",onSubmit:this.onSubmit,onReset:this.onReset,autoComplete:"off",noValidate:!0},!0===this.state._requiredText?h("p",null,h(KolIndentedTextTag,null,translate("kol-form-description"))):"string"==typeof this.state._requiredText&&this.state._requiredText.length>0?h("p",null,h(KolIndentedTextTag,null,this.state._requiredText)):null,h("slot",{key:"235d3db4100f7f872803573a909f11c137f4504c"})))}async focusErrorList(){return setTimeout((()=>{var t;this._errorList&&this._errorList.length>0&&(null===(t=this.errorListElement)||void 0===t||t.focus())}),300),Promise.resolve()}validateOn(t){"object"==typeof t&&null!==t&&(this.state=Object.assign(Object.assign({},this.state),{_on:t}))}validateRequiredText(t){"boolean"==typeof t?watchBoolean(this,"_requiredText",t):watchString(this,"_requiredText",t)}validateErrorList(t){validateErrorList(this,t)}componentWillLoad(){this.validateOn(this._on),this.validateRequiredText(this._requiredText),this.validateErrorList(this._errorList)}static get watchers(){return{_on:["validateOn"],_requiredText:["validateRequiredText"],_errorList:["validateErrorList"]}}},[1,"kol-form",{_on:[16],_requiredText:[8,"_required-text"],_errorList:[16],state:[32],focusErrorList:[64]},void 0,{_on:["validateOn"],_requiredText:["validateRequiredText"],_errorList:["validateErrorList"]}]);function defineCustomElement$1(){if("undefined"==typeof customElements)return;["kol-form"].forEach((t=>{if("kol-form"===t)customElements.get(t)||customElements.define(t,KolForm$1)}))}const KolForm=KolForm$1,defineCustomElement=defineCustomElement$1;export{KolForm,defineCustomElement};