// All material copyright ESRI, All Rights Reserved, unless otherwise specified.
// See http://@sbaseurl@/jsapi/jsapi/esri/copyright.txt and http://www.arcgis.com/apps/webappbuilder/copyright.txt for details.

//>>built
define(["dojo/_base/declare","dojo/_base/lang","dojo/topic","./SyncMapState"],function(g,b,f,h){var c=null;var e=g(null,{map:null,isMainView:!0,syncEventKey:"wab_sync_event",constructor:function(){window.localStorage?(this._windows=[],this.isMainView="false"===window.queryObject.ismain?!1:!0,this.syncMapState=h.getInstance(),f.subscribe("mapLoaded",b.hitch(this,this._onMapLoaded)),f.subscribe("mapChanged",b.hitch(this,this._onMapChanged)),this.isMainView||this._listenSyncEvent()):console.error("Localstorage is not supported by your browser, so the sync between browsers are not supported.")},
_onMapLoaded:function(a){this.map=a;this.syncMapState.setMap(a);this._bindMapEvents()},_onMapChanged:function(a){this.map=a;this.syncMapState.setMap(a);this._bindMapEvents()},_bindMapEvents:function(){this.map.on("extent-change",b.hitch(this,function(a){this._broadcastMapEvent("extent-change",a.extent)}))},_broadcastMapEvent:function(a,d){this._broadcastEvent("map/"+a,d)},_broadcastEvent:function(a,d){localStorage.setItem(this.syncEventKey,JSON.stringify({evtName:"sync/"+a,evt:d}))},_listenSyncEvent:function(){window.addEventListener("storage",
b.hitch(this,function(a){a.key===this.syncEventKey&&(a=JSON.parse(window.localStorage.getItem(a.key)),/^sync\/map/.test(a.evtName)&&this.syncMapState.handleMapChangeEvent(a))}))}});e.getInstance=function(){null===c&&(c=new e);return c};return e});