// 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/Deferred dojo/json esri/geometry/Extent esri/SpatialReference libs/storejs/store libs/md5/md5 jimu/tokenUtils".split(" "),function(l,m,n,p,q,r,f,t,h){var e=null,g=l(null,{rawAppConfig:null,mapMd5:null,appStateKey:null,setRawAppConfig:function(a){this.rawAppConfig=a},_getAppStateMd5:function(){if("string"!==typeof this.mapMd5){var a=p.stringify(this.rawAppConfig.map);this.mapMd5=t(a)}return this.mapMd5},_getAppStateKey:function(){return this.appStateKey?
this.appStateKey:this.appStateKey="wab_appstate_"+this.urlParams.id||this.urlParams.appid||window.path},getWabAppState:function(){var a=new n,d={};if(h.isInConfigOrPreviewWindow()||!this.rawAppConfig||!this.rawAppConfig.map)return a.resolve(d),a;var c=this._getAppStateKey(),b=f.get(c);b&&b.appStateMd5===this._getAppStateMd5()?(c=b.map&&b.map.extent,b=b.map&&b.map.layers,c&&(d.extent=new q(c.xmin,c.ymin,c.xmax,c.ymax,new r(c.spatialReference))),b&&(d.layers=b)):f.remove(c);a.resolve(d);return a},saveWabAppState:function(a,
d){if(a&&!h.isInConfigOrPreviewWindow()){var c=this._getAppStateKey(),b={extent:{xmin:a.extent.xmin,xmax:a.extent.xmax,ymin:a.extent.ymin,ymax:a.extent.ymax,spatialReference:{wkid:a.extent.spatialReference.wkid,wkt:a.extent.spatialReference.wkt}},layers:{}};d&&d.traversal&&d.traversal(m.hitch(this,function(k){b.layers[k.id]={visible:k.isVisible()}}));f.set(c,{map:b,appStateMd5:this._getAppStateMd5()})}}});g.getInstance=function(a){null===e&&(e=new g);e.urlParams=a;return e};return g});