/*!
 * KoliBri - The accessible HTML-Standard
 */
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});const index=require("./index-5cf289dd.js"),i18n=require("./i18n-86815e80.js"),componentNames=require("./component-names-b370a3a3.js"),prop_validators=require("./prop.validators-476ef807.js");require("./i18n-bbd0642f.js"),require("./reuse-daa2baf3.js"),require("./index-1285d2d1.js"),require("./dev.utils-3e595d38.js");const validateErrorList=(e,t)=>{prop_validators.watchValidator(e,"errorList",(e=>"object"==typeof e),new Set(["Object"]),t)},KolForm=class{constructor(e){index.registerInstance(this,e),this.onSubmit=e=>{var t,i;e.preventDefault(),e.stopPropagation(),"function"==typeof(null===(t=this.state._on)||void 0===t?void 0:t.onSubmit)&&(null===(i=this.state._on)||void 0===i||i.onSubmit(e))},this.onReset=e=>{var t,i;e.preventDefault(),e.stopPropagation(),"function"==typeof(null===(t=this.state._on)||void 0===t?void 0:t.onReset)&&(null===(i=this.state._on)||void 0===i||i.onReset(e))},this.handleLinkClick=e=>{var t;const i=null===(t=e.target)||void 0===t?void 0:t.href;if(i){const e=new URL(i),t=document.querySelector(e.hash);t&&"function"==typeof t.focus&&(t.scrollIntoView({behavior:"smooth"}),t.focus())}},this._on=void 0,this._requiredText=!0,this._errorList=void 0,this.state={}}render(){return index.h(index.Host,{key:"005270f9d4c739b5f2b399546d91dc8559bb45db",class:"kol-form"},this._errorList&&this._errorList.length>0&&index.h(componentNames.KolAlertTag,{key:"7acdf57b3f0954ee26df575334f7521d1898a597",_type:"error"},i18n.translate("kol-error-list-message"),index.h("nav",{key:"f16799bcbb7f60baec798674acb9f38c28424ce0","aria-label":i18n.translate("kol-error-list")},index.h("ul",{key:"8c86a5fa750031073142d383d1806bcae7a9eec6"},this._errorList.map(((e,t)=>index.h("li",{key:t},index.h(componentNames.KolLinkTag,{_href:e.selector,_label:e.message,_on:{onClick:this.handleLinkClick},ref:e=>{0===t&&(this.errorListElement=e)}}))))))),index.h("form",{key:"a626ea1dc80b465abfc4153b4c2217a462e3faf0",method:"post",onSubmit:this.onSubmit,onReset:this.onReset,autoComplete:"off",noValidate:!0},!0===this.state._requiredText?index.h("p",null,index.h(componentNames.KolIndentedTextTag,null,i18n.translate("kol-form-description"))):"string"==typeof this.state._requiredText&&this.state._requiredText.length>0?index.h("p",null,index.h(componentNames.KolIndentedTextTag,null,this.state._requiredText)):null,index.h("slot",{key:"05b129e368edc5151a8e3b19bc696b749be3db2a"})))}async focusErrorList(){return setTimeout((()=>{var e;this._errorList&&this._errorList.length>0&&(null===(e=this.errorListElement)||void 0===e||e.focus())}),300),Promise.resolve()}validateOn(e){"object"==typeof e&&null!==e&&(this.state=Object.assign(Object.assign({},this.state),{_on:e}))}validateRequiredText(e){"boolean"==typeof e?prop_validators.watchBoolean(this,"_requiredText",e):prop_validators.watchString(this,"_requiredText",e)}validateErrorList(e){validateErrorList(this,e)}componentWillLoad(){this.validateOn(this._on),this.validateRequiredText(this._requiredText),this.validateErrorList(this._errorList)}static get watchers(){return{_on:["validateOn"],_requiredText:["validateRequiredText"],_errorList:["validateErrorList"]}}};exports.kol_form=KolForm;