/*!
 * KoliBri - The accessible HTML-Standard
 */
import{r as registerInstance,h,H as Host}from"./index-9ca46203.js";import{z as watchBoolean,A as watchString,B as validateErrorList}from"./index-0489af72.js";import{t as translate}from"./i18n-3bac791b.js";import{j as KolIndentedTextTag,k as KolAlertTag,h as KolLinkTag}from"./component-names-61247f2f.js";import"./i18n-fddf0324.js";const 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:"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"]}}};export{KolForm as kol_form};