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