/*!
 * KoliBri - The accessible HTML-Standard
 */
import{r as registerInstance,h}from"./index-a5e15b1e.js";import{B as watchBoolean,C as watchString,D as validateErrorList}from"./index-c3ae175d.js";import{a as translate}from"./i18n-73edd5e1.js";import"./index-eb50dd62.js";import"./dev.utils-c7d151c6.js";const KolForm=class{constructor(t){registerInstance(this,t),this.onSubmit=t=>{var e,i;t.preventDefault(),t.stopPropagation(),"function"==typeof(null===(e=this.state._on)||void 0===e?void 0:e.onSubmit)&&(null===(i=this.state._on)||void 0===i||i.onSubmit(t))},this.onReset=t=>{var e,i;t.preventDefault(),t.stopPropagation(),"function"==typeof(null===(e=this.state._on)||void 0===e?void 0:e.onReset)&&(null===(i=this.state._on)||void 0===i||i.onReset(t))},this.handleLinkClick=t=>{var e;const i=null===(e=t.target)||void 0===e?void 0:e.href;if(i){const t=new URL(i),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("form",{method:"post",onSubmit:this.onSubmit,onReset:this.onReset,autoComplete:"off",noValidate:!0},this._errorList&&this._errorList.length>0&&h("kol-alert",{_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("kol-link",{_href:t.selector,_label:t.message,_on:{onClick:this.handleLinkClick},ref:t=>{0===e&&(this.errorListElement=t)}}))))))),!0===this.state._requiredText?h("p",null,h("kol-indented-text",null,translate("kol-form-description"))):"string"==typeof this.state._requiredText&&this.state._requiredText.length>0?h("p",null,h("kol-indented-text",null,this.state._requiredText)):null,h("slot",null))}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)}componentDidRender(){var t;this._errorList&&this._errorList.length>0&&(null===(t=this.errorListElement)||void 0===t||t.focus())}static get watchers(){return{_on:["validateOn"],_requiredText:["validateRequiredText"],_errorList:["validateErrorList"]}}};export{KolForm as kol_form};