import*as tslib_1 from"../polyfills/tslib.js";import{a as timer,b as fromEvent}from"./chunk-237a2f57.js";import{a as BaseService,b as PermissionsService,c as User,d as Util,e as DomUtil}from"./chunk-f41c48db.js";var singleton=Symbol(),singletonEnforcer=Symbol(),AppService=function(){function t(t){if(this.state={},this.baseUrl="",this.loading=!0,this.authenticated=!1,this.errorMessage="",t!==singletonEnforcer)throw new Error("Cannot construct singleton");this.base=BaseService.instance,this.permissions=PermissionsService.instance,this.translation=this.base.translation,this.config=this.base.config,this.user=new User("visitor")}return t.prototype.init=function(){return tslib_1.__awaiter(this,void 0,void 0,function(){var t,s,e,i,n=this;return tslib_1.__generator(this,function(o){switch(o.label){case 0:return[4,this.base.initApp(this.baseUrl+"/assets/config.json",!0,"_emaApp")];case 1:return o.sent(),[4,this.permissions.loadRules(this.baseUrl+"/assets/permissions.json",!0,"rules")];case 2:return o.sent(),this.base.translation.use(this.config.get("language")),this.data={},t=this.data,[4,Util.fetchJson(this.baseUrl+"/assets/collection-manifest.json")];case 3:return t.manifest=o.sent(),s=this.data,[4,Util.fetchJson(this.baseUrl+"/assets/data/mock-data.json")];case 4:return s.mockData=o.sent(),e=this.data,[4,Util.fetchJson(this.baseUrl+"/assets/data/mock-dwp.json")];case 5:return e.dwpData=o.sent(),i=this.data,[4,Util.fetchJson(this.baseUrl+"/assets/data/apiSwagger.json")];case 6:return i.swaggerData=o.sent(),this.collectionManifest=this.data.manifest,this.parseComponents(),this.initHistory(),this.initSketchListeners(),window.document.location.hostname.match("localhost")&&(this.config.set("dev",!0),DomUtil.addClass(document.getElementsByTagName("body")[0],"dev")),this.state.initialized=!0,timer(200).subscribe(function(){n.initLoginForm()}),[2]}})})},t.prototype.initLoginForm=function(){this.loginForm=document.getElementById("app-login-form"),fromEvent(this.loginForm,"formSubmit").subscribe(function(t){console.log("app-login-form",t.detail)})},t.prototype.initSketchListeners=function(){var t=this;fromEvent(document,"sketch-artboard-init").subscribe(function(t){console.log("sketch init: ",t.detail.selector)}),fromEvent(document,"sketch-artboard-update").subscribe(function(t){console.log("sketch update: ",t.detail.selector)}),fromEvent(document,"svgElementClick").subscribe(function(s){var e=s.detail.id;e.match("btn-logo")&&t.showFlashMessage("Called from sketch: id="+e,"primary",2e3),e.match("icon-sketch"),console.log("svg: id = ",s.detail.id)})},t.prototype.initHistory=function(){"undefined"!=typeof window&&window},t.prototype.parseComponents=function(){var t=this,s=Util.copy(this.data.manifest.components),e=[];s.map(function(s){var i=s.tag,n=!1;t.config.get("componentsIgnorePatterns").forEach(function(t){i.match(t)&&(n=!0)}),n||e.push(s)}),this.components=e},t.prototype.showFlashMessage=function(t,s,e){void 0===e&&(e=2e3),document.querySelector("ema-flash-message").show(t,s,e)},Object.defineProperty(t,"instance",{get:function(){return this[singleton]||(this[singleton]=new t(singletonEnforcer)),this[singleton]},enumerable:!0,configurable:!0}),t}();export{AppService as a};