/*!
 * KoliBri - The accessible HTML-Standard
 */
import{r as t,h as i}from"./index-a5e15b1e.js";import{B as e,C as o,D as s}from"./index-c3ae175d.js";import{a as r}from"./i18n-73edd5e1.js";import"./index-eb50dd62.js";import"./dev.utils-c7d151c6.js";const l=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("form",{method:"post",onSubmit:this.onSubmit,onReset:this.onReset,autoComplete:"off",noValidate:!0},this._errorList&&this._errorList.length>0&&i("kol-alert",{_type:"error"},r("kol-error-list-message"),i("nav",{"aria-label":r("kol-error-list")},i("ul",null,this._errorList.map(((t,e)=>i("li",{key:e},i("kol-link",{_href:t.selector,_label:t.message,_on:{onClick:this.handleLinkClick},ref:t=>{0===e&&(this.errorListElement=t)}}))))))),!0===this.state._requiredText?i("p",null,i("kol-indented-text",null,r("kol-form-description"))):"string"==typeof this.state._requiredText&&this.state._requiredText.length>0?i("p",null,i("kol-indented-text",null,this.state._requiredText)):null,i("slot",null))}validateOn(t){"object"==typeof t&&null!==t&&(this.state=Object.assign(Object.assign({},this.state),{_on:t}))}validateRequiredText(t){"boolean"==typeof t?e(this,"_requiredText",t):o(this,"_requiredText",t)}validateErrorList(t){s(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{l as kol_form};