/*!
 * KoliBri - The accessible HTML-Standard
 */
import{r as t,h as i,H as e}from"./index-9ca46203.js";import{z as s,A as o,B as r}from"./index-0489af72.js";import{t as n}from"./i18n-3bac791b.js";import{j as l,k as a,h as f}from"./component-names-61247f2f.js";import"./i18n-fddf0324.js";const d=class{constructor(e){t(this,e),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 i(e,{key:"65d715836bb74ba26265a82596c68938518f1bd6",class:"kol-form"},this._errorList&&this._errorList.length>0&&i(a,{_type:"error"},n("kol-error-list-message"),i("nav",{"aria-label":n("kol-error-list")},i("ul",null,this._errorList.map(((t,e)=>i("li",{key:e},i(f,{_href:t.selector,_label:t.message,_on:{onClick:this.handleLinkClick},ref:t=>{0===e&&(this.errorListElement=t)}}))))))),i("form",{key:"47ab1f7b0e6ab78c81d63e073b9cde8baf007f39",method:"post",onSubmit:this.onSubmit,onReset:this.onReset,autoComplete:"off",noValidate:!0},!0===this.state._requiredText?i("p",null,i(l,null,n("kol-form-description"))):"string"==typeof this.state._requiredText&&this.state._requiredText.length>0?i("p",null,i(l,null,this.state._requiredText)):null,i("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?s(this,"_requiredText",t):o(this,"_requiredText",t)}validateErrorList(t){r(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{d as kol_form};