/*!
 * KoliBri - The accessible HTML-Standard
 */
import{proxyCustomElement,HTMLElement,h}from"@stencil/core/internal/client";import{k as watchBoolean,w as watchString,aa as validateErrorList}from"./index2.js";import{a as translate}from"./i18n.js";import{d as defineCustomElement$b}from"./shadow.js";import{d as defineCustomElement$a}from"./component6.js";import{d as defineCustomElement$9}from"./component5.js";import{d as defineCustomElement$8}from"./component4.js";import{d as defineCustomElement$7}from"./component.js";import{d as defineCustomElement$6}from"./component11.js";import{d as defineCustomElement$5}from"./shadow2.js";import{d as defineCustomElement$4}from"./component9.js";import{d as defineCustomElement$3}from"./component2.js";import{d as defineCustomElement$2}from"./component3.js";const KolForm$1=proxyCustomElement(class extends HTMLElement{constructor(){super(),this.__registerHost(),this.__attachShadow(),this.onSubmit=e=>{var t,o;e.preventDefault(),e.stopPropagation(),"function"==typeof(null===(t=this.state._on)||void 0===t?void 0:t.onSubmit)&&(null===(o=this.state._on)||void 0===o||o.onSubmit(e))},this.onReset=e=>{var t,o;e.preventDefault(),e.stopPropagation(),"function"==typeof(null===(t=this.state._on)||void 0===t?void 0:t.onReset)&&(null===(o=this.state._on)||void 0===o||o.onReset(e))},this.handleLinkClick=e=>{var t;const o=null===(t=e.target)||void 0===t?void 0:t.href;if(o){const e=new URL(o),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 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(((e,t)=>h("li",{key:t},h("kol-link",{_href:e.selector,_label:e.message,_on:{onClick:this.handleLinkClick},ref:e=>{0===t&&(this.errorListElement=e)}}))))))),!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(e){"object"==typeof e&&null!==e&&(this.state=Object.assign(Object.assign({},this.state),{_on:e}))}validateRequiredText(e){"boolean"==typeof e?watchBoolean(this,"_requiredText",e):watchString(this,"_requiredText",e)}validateErrorList(e){validateErrorList(this,e)}componentWillLoad(){this.validateOn(this._on),this.validateRequiredText(this._requiredText),this.validateErrorList(this._errorList)}componentDidRender(){var e;this._errorList&&this._errorList.length>0&&(null===(e=this.errorListElement)||void 0===e||e.focus())}static get watchers(){return{_on:["validateOn"],_requiredText:["validateRequiredText"],_errorList:["validateErrorList"]}}},[1,"kol-form",{_on:[16],_requiredText:[8,"_required-text"],_errorList:[16],state:[32]},void 0,{_on:["validateOn"],_requiredText:["validateRequiredText"],_errorList:["validateErrorList"]}]);function defineCustomElement$1(){if("undefined"==typeof customElements)return;["kol-form","kol-alert","kol-alert-wc","kol-button-wc","kol-heading-wc","kol-icon","kol-indented-text","kol-link","kol-link-wc","kol-span-wc","kol-tooltip-wc"].forEach((e=>{switch(e){case"kol-form":customElements.get(e)||customElements.define(e,KolForm$1);break;case"kol-alert":customElements.get(e)||defineCustomElement$b();break;case"kol-alert-wc":customElements.get(e)||defineCustomElement$a();break;case"kol-button-wc":customElements.get(e)||defineCustomElement$9();break;case"kol-heading-wc":customElements.get(e)||defineCustomElement$8();break;case"kol-icon":customElements.get(e)||defineCustomElement$7();break;case"kol-indented-text":customElements.get(e)||defineCustomElement$6();break;case"kol-link":customElements.get(e)||defineCustomElement$5();break;case"kol-link-wc":customElements.get(e)||defineCustomElement$4();break;case"kol-span-wc":customElements.get(e)||defineCustomElement$3();break;case"kol-tooltip-wc":customElements.get(e)||defineCustomElement$2()}}))}const KolForm=KolForm$1,defineCustomElement=defineCustomElement$1;export{KolForm,defineCustomElement};