import{r as e,e as t,h as r,d as i}from"./p-5ab6b26f.js";import{_ as s}from"./p-a41b3114.js";class a{constructor(r){e(this,r),this.formId=`gl-form-${l++}`,this.translateText=!1,this.glFormCancel=t(this,"glFormCancel",7),this.glFormFeatureChanged=t(this,"glFormFeatureChanged",7),this.glFormSubmit=t(this,"glFormSubmit",7)}async componentWillLoad(){let e=await fetch(this.schema);this._schema=await e.json()}componentDidLoad(){let e=this.createFormPage(this.label);this.el.querySelector("ion-nav").setRoot(e)}setValue(e){this.feature&&(this.feature.properties=this.feature.properties||{},this.feature.properties[e.detail.field.attribute]=e.detail.value,this.glFormFeatureChanged.emit({formId:this.formId,feature:this.feature}))}handleFacet(e){let t=this.createFormPage(e.detail.label,e.detail.value);this.el.querySelector("ion-nav").push(t)}async cancel(){this.glFormCancel.emit({formId:this.formId,feature:this.feature})}async submit(){this.glFormSubmit.emit({formId:this.formId,feature:this.feature})}createFormPage(e,t){let r=document.createElement("gl-form-page");return r.formFacet=t,r.facets=this.filter(this._schema.facets||[],t),r.fields=this.filter(this._schema.fields||[],t),r.root=!t,e&&(r.label=e),this.submitText&&(r.submitText=this.submitText),this.cancelText&&(r.cancelText=this.cancelText),r}filter(e,t){return e.filter(e=>{let r=e.facets||[];if(!r.length&&!t)return!0;for(let e of r){let r=e.replace(/[.?+^$[\]\\(){}|-]/g,"\\$&");if(new RegExp("^"+r.split("*").join(".*")+"$").test(t))return!0}return!1}).map(e=>{let r=Object.assign({},e);return this.translateText&&(r.label=s(e.label)),e.options&&(r.options=this.filter(e.options,t)),r})}render(){return r("ion-nav",null)}get el(){return i(this)}}let l=0;export{a as gl_form};