// 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/_base/html dijit/_WidgetBase dojo/topic dojo/on dojo/query dojo/Deferred dojo/promise/all dojo/debounce require ./MapManager ./utils".split(" "),function(q,d,e,r,f,n,t,l,p,u,g,v,h){var k=null;var m=q([r],{constructor:function(a,b){this.own(f.subscribe("appConfigLoaded",d.hitch(this,this._onAppConfigLoaded)));this.own(f.subscribe("appConfigChanged",d.hitch(this,this._onAppConfigChanged)));this.own(f.subscribe("mapLoaded",d.hitch(this,this._onMapLoaded)));
this.own(f.subscribe("mapChanged",d.hitch(this,this._onMapChanged)));this.own(f.subscribe("beforeMapDestory",d.hitch(this,this._onBeforeMapDestory)));this.own(f.subscribe("preloadModulesLoaded",d.hitch(this,this._onPreloadModulesLoaded)));this.own(f.subscribe("openWidget",d.hitch(this,this._onOpenWidgetRequest)));this.own(f.subscribe("builder/actionTriggered",d.hitch(this,this._onActionTriggered)));h.isMobileUa()||this.own(n(window,"resize",u(d.hitch(this,this.resize),200)));this.id=b;this.preloadModulesLoadDef=
new l},postCreate:function(){this.containerNode=this.domNode},map:null,mapId:"map",mapDiv:null,hlDiv:null,layoutManager:null,animTime:500,resize:function(){this.layoutManager&&this.layoutManager.resize()},_onAppConfigLoaded:function(a){this.appConfig=d.clone(a);this.preloadModulesLoadDef.then(d.hitch(this,function(){this._loadLayoutManager(this.appConfig).then(d.hitch(this,function(b){this.layoutManager=b;this.layoutManager.onEnter(this.appConfig,this.mapId).then(d.hitch(this,function(){this.mapDiv=
this.layoutManager.getMapDiv();this._loadingAnim();this._loadMap(this.mapId);this.appConfig.theme&&this._loadTheme(this.appConfig.theme)}))}))}))},_loadLayoutManager:function(a){a=a.layoutDefinition?a.layoutDefinition.manager:"jimu/layoutManagers/AbsolutePositionLayoutManager";var b=new l;g([a],d.hitch(this,function(c){c=c.getInstance();this.map&&c.setMap(this.map);b.resolve(c)}));return b},_loadingAnim:function(){window.isXT&&"config"===this.appConfig.mode||(e.addClass(jimuConfig.loadingId,"loading-fadeOut"),
this.own(n(document.getElementById(jimuConfig.loadingId),"animationend",d.hitch(this,function(){e.setStyle(jimuConfig.loadingId,"display","none")}))))},_loadMap:function(a){this.mapManager=v.getInstance({appConfig:this.appConfig,urlParams:this.urlParams},a);this.mapManager.showMap();this._lazyLoadResources()},_lazyLoadResources:function(){jimuConfig.lazyLoadCss&&g(jimuConfig.lazyLoadCss);g(["dynamic-modules/commonResources"])},_onMapLoaded:function(a){this.map=a;this.layoutManager.setMap(a);this.layoutManager.loadAndLayout(this.appConfig)},
_onPreloadModulesLoaded:function(){this.preloadModulesLoadDef.resolve()},_loadTheme:function(a){var b=new l;g(["themes/"+a.name+"/main"],d.hitch(this,function(){p([this._loadThemeCommonStyle(a),this._loadThemeCurrentStyle(a)]).then(d.hitch(this,function(){this._addCustomStyle(a);this.layoutManager.onThemeLoad();b.resolve()}))}));return b},_loadThemeCommonStyle:function(a){e.addClass(this.domNode,a.name);return h.loadStyleLink(this._getThemeCommonStyleId(a),"themes/"+a.name+"/common.css")},_loadThemeCurrentStyle:function(a){e.addClass(this.domNode,
a.styles[0]);return h.loadStyleLink(this._getThemeCurrentStyleId(a),"themes/"+a.name+"/styles/"+a.styles[0]+"/style.css")},_addCustomStyle:function(a){var b=d.getObject("customStyles",!1,a);if(b){var c=".jimu-main-background{background-color: ${mainBackgroundColor} !important;}";(a=this._getFixedThemeStyles(a))&&(c+=a);c=d.replace(c,b,/\$\{([^\}]+)\}/g);b=e.create("style",{type:"text/css"});try{b.appendChild(document.createTextNode(c))}catch(w){b.styleSheet.cssText=c}b.setAttribute("source","custom");
document.head.appendChild(b)}},_getFixedThemeStyles:function(a){var b=".esriPopup .titlePane {background-color: ${mainBackgroundColor} !important;}";if(a.customStyles.mainBackgroundColor&&h.isLightColor(a.customStyles.mainBackgroundColor)){var c=g.toUrl("jimu")+"/css/images/api_popup_light.png";b+=".esriPopup .titleButton {background: url("+c+") no-repeat}.esriPopup .titlePane {color: black}"}"PlateauTheme"===a.name?b+=".jimu-widget-header-controller .jimu-title, .jimu-widget-header-controller .jimu-subtitle{color: ${mainBackgroundColor} !important;}.jimu-widget-header-controller .links .jimu-link{color: ${mainBackgroundColor} !important;}.jimu-widget-homebutton .HomeButton .home, .jimu-widget-mylocation, .jimu-widget-mylocation .place-holder, .jimu-widget-zoomslider.vertical .zoom-in, .jimu-widget-zoomslider.vertical .zoom-out, .jimu-widget-extent-navigate.vertical .operation{background-color: ${mainBackgroundColor} !important;}.jimu-preload-widget-icon-panel \x3e .jimu-panel-title, .jimu-foldable-panel \x3e .jimu-panel-title, .jimu-title-panel \x3e .title{color: ${mainBackgroundColor} !important;}.jimu-panel{border-color: ${mainBackgroundColor} !important;}.jimu-widget-header-controller{border-bottom-color: ${mainBackgroundColor} !important;}.jimu-tab\x3e.control\x3e.tab{color: ${mainBackgroundColor} !important; border-color: ${mainBackgroundColor} !important} .popup-links .title, .popup-links a, .popup-links, .popup-links .line { color: ${mainBackgroundColor} ; border-color: ${mainBackgroundColor};}":
"BillboardTheme"===a.name?b+=".jimu-widget-homebutton .HomeButton .home, .jimu-widget-mylocation .place-holder, .jimu-widget-zoomslider.vertical .zoom-in, .jimu-widget-zoomslider.vertical .zoom-out, .jimu-widget-extent-navigate .operation, .jimu-widget-fullScreen .fullScreen, .jimu-widget-mylocation .place-holder.nohttps:hover, .jimu-widget-extent-navigate .operation.jimu-state-disabled:hover{background-color: ${mainBackgroundColor} !important; opacity: 0.8;}.jimu-widget-onscreen-icon{background-color: ${mainBackgroundColor} !important; opacity: 0.8;}.jimu-widget-homebutton .HomeButton .home:hover, .jimu-widget-mylocation .place-holder:not(.nohttps):hover, .jimu-widget-zoomslider.vertical .zoom-in:hover, .jimu-widget-zoomslider.vertical .zoom-out:hover, .jimu-widget-extent-navigate .operation:not(.jimu-state-disabled):hover, .jimu-widget-fullScreen .fullScreen:hover, .jimu-widget-onscreen-icon:hover, .jimu-widget-onscreen-icon.jimu-state-selected{opacity: 1;}":
"BoxTheme"===a.name?b+=".jimu-widget-homebutton .HomeButton .home, .jimu-widget-mylocation .place-holder, .jimu-widget-zoomslider.vertical .zoom-in, .jimu-widget-zoomslider.vertical .zoom-out, .jimu-widget-extent-navigate .operation, .jimu-widget-fullScreen .fullScreen{background-color: ${mainBackgroundColor} !important; opacity: 0.8;}.jimu-main-background.jimu-widget-zoomslider{background-color: transparent !important}.jimu-widget-homebutton .HomeButton .home:hover, .jimu-widget-mylocation .place-holder:not(.nohttps):hover, .jimu-widget-zoomslider.vertical .zoom-in:hover, .jimu-widget-zoomslider.vertical .zoom-out:hover, .jimu-widget-zoomslider .zoom:hover, .jimu-widget-extent-navigate .operation:not(.jimu-state-disabled):hover, .jimu-widget-fullScreen .fullScreen:hover{background-color: ${mainBackgroundColor} !important; opacity: 1;}":
"TabTheme"===a.name?b+=".tab-widget-frame .title-label{color: ${mainBackgroundColor} !important;}":"DartTheme"===a.name?b+=".jimu-widget-fullScreen .fullScreen{background-color: ${mainBackgroundColor} !important;}.dart-controller-extent-navigate .jimu-widget-extent-navigate .operation.jimu-state-disabled,.dart-controller-extent-navigate .jimu-widget-extent-navigate .operation.jimu-state-disabled:hover{color: ${mainBackgroundColor} !important; opacity: 0.6;}.dart-controller-extent-navigate .jimu-widget-extent-navigate .operation,.dart-controller-extent-navigate .jimu-widget-extent-navigate .operation:hover{color: ${mainBackgroundColor} !important; opacity: 1;}":
"PocketTheme"===a.name&&(b+=".jimu-main-background, .jimu-widget-homebutton, .jimu-widget-mylocation, .jimu-widget-onscreen-icon, .jimu-widget-onscreen-icon.jimu-state-selected, .jimu-widget-zoomslider .zoom, .jimu-widget-homebutton .HomeButton .home, .jimu-widget-mylocation .place-holder, .jimu-widget-extent-navigate .operation, .jimu-widget-fullScreen .fullScreen, .esriPopup .titlePane, .esriPopupMobile .titlePane, .esriPopup .pointer.top{background-color: ${mainBackgroundColor} !important;}.esriMobileNavigationBar{background-color: ${mainBackgroundColor} !important; background-image: none !important;}");
return b},_onAppConfigChanged:function(a,b,c){a=d.clone(a);switch(b){case "themeChange":this._onThemeChange(a);break;case "styleChange":this._onStyleChange(a);break;case "layoutChange":this._onLayoutChange(a);break;case "widgetChange":this._onWidgetChange(a,c);break;case "groupChange":this._onGroupChange(a,c);break;case "widgetPoolChange":this._onWidgetPoolChange(a,c);break;case "resetConfig":this._onResetConfig(a);break;case "loadingPageChange":this._onLoadingPageChange(a,c);break;case "layoutDefinitionChange":this._onLayoutDefinitionChange(a,
c);break;case "onScreenGroupsChange":this._onOnScreenGroupsChange(a,c);break;case "onScreenOrderChange":this._onOnScreenOrderChange(a,c)}this.appConfig=a},_onMapChanged:function(a){this.map=a;this.layoutManager.setMap(a);this.layoutManager.loadAndLayout(this.appConfig)},_onBeforeMapDestory:function(){this.layoutManager.destroyOnScreenWidgetsAndGroups()},_onThemeChange:function(a){this.layoutManager.destroyOnScreenWidgetsAndGroups();this._removeThemeCommonStyle(this.appConfig.theme);this._removeThemeCurrentStyle(this.appConfig.theme);
this._removeCustomStyle();p([this._loadLayoutManager(a),this._loadTheme(a.theme)]).then(d.hitch(this,function(b){var c=b[0];this.layoutManager.name!==c.name?(this.layoutManager.onLeave(),c.onEnter(a,this.mapId).then(d.hitch(this,function(){this.layoutManager=c;this.layoutManager.loadAndLayout(a)}))):this.layoutManager.loadAndLayout(a)}))},_onResetConfig:function(a){var b=this.appConfig;f.publish("appConfigChanged",a,"mapChange",a);this.appConfig=b;this._loadLayoutManager(a).then(d.hitch(this,function(c){this.layoutManager=
c;this._removeThemeCommonStyle(this.appConfig.theme);this._removeThemeCurrentStyle(this.appConfig.theme);this._removeCustomStyle();this._loadTheme(this.appConfig.theme)}))},_onLoadingPageChange:function(a,b){"backgroundColor"in b?e.setStyle(jimuConfig.loadingId,"background-color",a.loadingPage.backgroundColor):"backgroundImage"in b?(a=a.loadingPage.backgroundImage,a.visible&&a.uri?(e.setStyle(jimuConfig.loadingImageId,"background-image","url('"+a.uri+"')"),e.setStyle(jimuConfig.loadingImageId,"width",
a.width+"px"),e.setStyle(jimuConfig.loadingImageId,"height",a.height+"px")):(e.setStyle(jimuConfig.loadingImageId,"background-image","url('')"),e.setStyle(jimuConfig.loadingImageId,"width","0px"),e.setStyle(jimuConfig.loadingImageId,"height","0px"))):"loadingGif"in b&&(a=a.loadingPage.loadingGif,a.visible&&a.uri?(e.setStyle(jimuConfig.loadingGifId,"background-image","url('"+a.uri+"')"),e.setStyle(jimuConfig.loadingGifId,"width",a.width+"px"),e.setStyle(jimuConfig.loadingGifId,"height",a.height+"px")):
(e.setStyle(jimuConfig.loadingGifId,"background-image","url('')"),e.setStyle(jimuConfig.loadingGifId,"width","0px"),e.setStyle(jimuConfig.loadingGifId,"height","0px")))},_onStyleChange:function(a){this._removeThemeCurrentStyle(this.appConfig.theme);this._loadThemeCurrentStyle(a.theme);this._removeCustomStyle();this._addCustomStyle(a.theme)},_onLayoutChange:function(a){this.layoutManager.onLayoutChange(a)},_onWidgetChange:function(a,b){this.layoutManager.onWidgetChange(a,b)},_onGroupChange:function(a,
b){this.layoutManager.onGroupChange(a,b)},_onWidgetPoolChange:function(a,b){this.layoutManager.onWidgetPoolChange(a,b)},_onActionTriggered:function(a){this.layoutManager.onActionTriggered(a)},_onLayoutDefinitionChange:function(a,b){this.layoutManager.onLayoutDefinitionChange(a,b)},_onOnScreenGroupsChange:function(a,b){this.layoutManager.onOnScreenGroupsChange(a,b)},_onOnScreenOrderChange:function(a,b){this.layoutManager.onOnScreenOrderChange(a,b)},_removeThemeCommonStyle:function(a){e.removeClass(this.domNode,
a.name);e.destroy(this._getThemeCommonStyleId(a))},_removeThemeCurrentStyle:function(a){e.removeClass(this.domNode,a.styles[0]);e.destroy(this._getThemeCurrentStyleId(a))},_removeCustomStyle:function(){t('style[source\x3d"custom"]',document.head).forEach(function(a){e.destroy(a)})},_getThemeCommonStyleId:function(a){return"theme_"+a.name+"_style_common"},_getThemeCurrentStyleId:function(a){return"theme_"+a.name+"_style_"+a.styles[0]},_onOpenWidgetRequest:function(a){this.layoutManager.openWidget(a)}});
m.getInstance=function(a,b){null===k&&(k=new m(a,b),window._layoutManager=k);return k};return m});