/*!
 * KoliBri - The accessible HTML-Standard
 */
import{proxyCustomElement,HTMLElement,h,Host}from"@stencil/core/internal/client";import{t as translate}from"./i18n2.js";import{m as KolAlertTag,h as KolLinkTag,l as KolIndentedTextTag}from"./component-names.js";import{w as watchValidator,c as watchBoolean,e as watchString}from"./prop.validators.js";const validateErrorList=(e,t)=>{watchValidator(e,"errorList",(e=>"object"==typeof e),new Set(["Object"]),t)},KolForm$1=proxyCustomElement(class extends HTMLElement{constructor(){super(),this.__registerHost(),this.__attachShadow(),this.onSubmit=e=>{var t,o;e.preventDefault(),e.stopPropagation(),"function"==typeof(null===(t=this.state._on)||void 0===t?void 0:t.onSubmit)&&(null===(o=this.state._on)||void 0===o||o.onSubmit(e))},this.onReset=e=>{var t,o;e.preventDefault(),e.stopPropagation(),"function"==typeof(null===(t=this.state._on)||void 0===t?void 0:t.onReset)&&(null===(o=this.state._on)||void 0===o||o.onReset(e))},this.handleLinkClick=e=>{var t;const o=null===(t=e.target)||void 0===t?void 0:t.href;if(o){const e=new URL(o),t=document.querySelector(e.hash);t&&"function"==typeof t.focus&&(t.scrollIntoView({behavior:"smooth"}),t.focus())}},this._on=void 0,this._requiredText=!0,this._errorList=void 0,this.state={}}render(){return h(Host,{key:"005270f9d4c739b5f2b399546d91dc8559bb45db",class:"kol-form"},this._errorList&&this._errorList.length>0&&h(KolAlertTag,{key:"7acdf57b3f0954ee26df575334f7521d1898a597",_type:"error"},translate("kol-error-list-message"),h("nav",{key:"f16799bcbb7f60baec798674acb9f38c28424ce0","aria-label":translate("kol-error-list")},h("ul",{key:"8c86a5fa750031073142d383d1806bcae7a9eec6"},this._errorList.map(((e,t)=>h("li",{key:t},h(KolLinkTag,{_href:e.selector,_label:e.message,_on:{onClick:this.handleLinkClick},ref:e=>{0===t&&(this.errorListElement=e)}}))))))),h("form",{key:"a626ea1dc80b465abfc4153b4c2217a462e3faf0",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:"05b129e368edc5151a8e3b19bc696b749be3db2a"})))}async focusErrorList(){return setTimeout((()=>{var e;this._errorList&&this._errorList.length>0&&(null===(e=this.errorListElement)||void 0===e||e.focus())}),300),Promise.resolve()}validateOn(e){"object"==typeof e&&null!==e&&(this.state=Object.assign(Object.assign({},this.state),{_on:e}))}validateRequiredText(e){"boolean"==typeof e?watchBoolean(this,"_requiredText",e):watchString(this,"_requiredText",e)}validateErrorList(e){validateErrorList(this,e)}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((e=>{if("kol-form"===e)customElements.get(e)||customElements.define(e,KolForm$1)}))}const KolForm=KolForm$1,defineCustomElement=defineCustomElement$1;export{KolForm,defineCustomElement};