import{a as s,b as t}from"./chunk-237a2f57.js";import{a as i,b as a,c as e,d as o,e as n}from"./chunk-f41c48db.js";const h=Symbol(),c=Symbol();class r{constructor(s){if(this.state={},this.baseUrl="",this.loading=!0,this.authenticated=!1,this.errorMessage="",s!==c)throw new Error("Cannot construct singleton");this.base=i.instance,this.permissions=a.instance,this.translation=this.base.translation,this.config=this.base.config,this.user=new e("visitor")}async init(){await this.base.initApp(this.baseUrl+"/assets/config.json",!0,"_emaApp"),await this.permissions.loadRules(this.baseUrl+"/assets/permissions.json",!0,"rules"),this.base.translation.use(this.config.get("language")),this.data={},this.data.manifest=await o.fetchJson(this.baseUrl+"/assets/collection-manifest.json"),this.data.mockData=await o.fetchJson(this.baseUrl+"/assets/data/mock-data.json"),this.data.dwpData=await o.fetchJson(this.baseUrl+"/assets/data/mock-dwp.json"),this.data.swaggerData=await o.fetchJson(this.baseUrl+"/assets/data/apiSwagger.json"),this.collectionManifest=this.data.manifest,this.parseComponents(),this.initHistory(),this.initSketchListeners(),window.document.location.hostname.match("localhost")&&(this.config.set("dev",!0),n.addClass(document.getElementsByTagName("body")[0],"dev")),this.state.initialized=!0,s(200).subscribe(()=>{this.initLoginForm()})}initLoginForm(){this.loginForm=document.getElementById("app-login-form"),t(this.loginForm,"formSubmit").subscribe(s=>{console.log("app-login-form",s.detail)})}initSketchListeners(){t(document,"sketch-artboard-init").subscribe(s=>{console.log("sketch init: ",s.detail.selector)}),t(document,"sketch-artboard-update").subscribe(s=>{console.log("sketch update: ",s.detail.selector)}),t(document,"svgElementClick").subscribe(s=>{let t=s.detail.id;t.match("btn-logo")&&this.showFlashMessage("Called from sketch: id="+t,"primary",2e3),t.match("icon-sketch"),console.log("svg: id = ",s.detail.id)})}initHistory(){"undefined"!=typeof window&&window}parseComponents(){let s=o.copy(this.data.manifest.components),t=[];s.map(s=>{let i=s.tag,a=!1;this.config.get("componentsIgnorePatterns").forEach(s=>{i.match(s)&&(a=!0)}),a||t.push(s)}),this.components=t}showFlashMessage(s,t,i=2e3){document.querySelector("ema-flash-message").show(s,t,i)}static get instance(){return this[h]||(this[h]=new r(c)),this[h]}}export{r as a};