/*!
 * KoliBri - The accessible HTML-Standard
 */
import{r as registerInstance,h,H as Host}from"./index-b2c61df0.js";import{t as translate}from"./i18n-112381e9.js";import{j as KolIndentedTextTag,k as KolAlertTag,h as KolLinkTag}from"./component-names-068dc2ae.js";import{w as watchValidator,b as watchBoolean,i as watchString}from"./prop.validators-db70e3c4.js";import"./i18n-66b52d13.js";import"./reuse-b66836de.js";import"./index-db4aa6e4.js";import"./dev.utils-1ca991a2.js";const validateErrorList=(t,e)=>{watchValidator(t,"errorList",(t=>"object"==typeof t),new Set(["Object"]),e)},KolForm=class{constructor(t){registerInstance(this,t),this.onSubmit=t=>{var e,r;t.preventDefault(),t.stopPropagation(),"function"==typeof(null===(e=this.state._on)||void 0===e?void 0:e.onSubmit)&&(null===(r=this.state._on)||void 0===r||r.onSubmit(t))},this.onReset=t=>{var e,r;t.preventDefault(),t.stopPropagation(),"function"==typeof(null===(e=this.state._on)||void 0===e?void 0:e.onReset)&&(null===(r=this.state._on)||void 0===r||r.onReset(t))},this.handleLinkClick=t=>{var e;const r=null===(e=t.target)||void 0===e?void 0:e.href;if(r){const t=new URL(r),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:"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(((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:"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 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"]}}};export{KolForm as kol_form};