// 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/array dojo/_base/html dijit/_WidgetBase dojo/Deferred dojo/promise/all ../utils ../WidgetPlaceholder ../OnScreenWidgetIcon ./A11yLayoutManager".split(" "),function(p,h,e,g,q,n,r,k,t,u,v){var m=null;var l=p([q],{constructor:function(){this.widgetPlaceholders=[];this.onScreenWidgetIcons=[];this.invisibleWidgetIds=[]},name:"BaseLayoutManager",mapId:"map",map:null,layoutId:"jimu-layout-manager",postCreate:function(){this.containerNode=this.domNode;
this.layoutId=jimuConfig.layoutId},resize:function(){},isSupportEdit:function(){return!1},getMapDiv:function(){},setMap:function(a){this.map=a},onEnter:function(a,b){var c=new n;this.appConfig=a;this.mapId=b;c.resolve();return c},onLeave:function(){},onThemeLoad:function(){},loadAndLayout:function(a){},openWidget:function(a){},onLayoutChange:function(a){},onWidgetChange:function(a,b){},onGroupChange:function(a,b){},onWidgetPoolChange:function(a,b){this.reloadControllerWidget(a,b.controllerId)},onOnScreenOrderChange:function(a,
b){e.forEach(b,h.hitch(this,function(c){c.uri?e.some(this.onScreenWidgetIcons,h.hitch(this,function(d){if(d.configId===c.id)return g.setStyle(d.domNode,k.getPositionStyle({top:c.position.top,left:c.position.left,right:c.position.right,bottom:c.position.bottom,width:40,height:40})),d.moveTo(c.position),!0})):e.some(this.widgetPlaceholders,h.hitch(this,function(d){if(d.index===c.placeholderIndex){var f=k.getPositionStyle({top:c.position.top,left:c.position.left,right:c.position.right,bottom:c.position.bottom,
width:40,height:40});g.setStyle(d.domNode,f);return!0}}))}))},onActionTriggered:function(a){},onLayoutDefinitionChange:function(a,b){},onOnScreenGroupsChange:function(a,b){},destroyOnScreenWidgetsAndGroups:function(a){},loadOnScreenWidgets:function(a){var b=[];e.forEach(a.widgetOnScreen.widgets,function(c){!1===c.visible?this.invisibleWidgetIds.push(c.id):b.push(this.loadOnScreenWidget(c,a))},this);return r(b)},loadOnScreenWidget:function(a,b){var c=new n;if("config"===b.mode&&!a.uri)return b=this._createOnScreenWidgetPlaceHolder(a),
c.resolve(b),c;if(!a.uri)return c.resolve(null),c;a.inPanel||a.closeable?(b=this._createOnScreenWidgetIcon(a),c.resolve(b)):this.widgetManager.loadWidget(a).then(h.hitch(this,function(d){try{d.setPosition(d.position),this.widgetManager.openWidget(d)}catch(f){console.log(console.error("fail to startup widget "+d.name+". "+f.stack))}d.configId=a.id;c.resolve(d)}),function(d){c.reject(d)});return c},onOnScreenWidgetChange:function(a,b){b=a.getConfigElementById(b.id);b.isController?this.reloadControllerWidget(a,
b.id):(e.forEach(this.widgetPlaceholders,function(c){c.configId===b.id&&(c.destroy(),this.loadOnScreenWidget(b,a))},this),this.removeDestroyed(this.widgetPlaceholders),this._updatePlaceholder(a),e.forEach(this.onScreenWidgetIcons,function(c){if(c.configId===b.id){var d=c.state;c.destroy();this.loadOnScreenWidget(b,a).then(function(f){if(b.uri&&"opened"===d)f.onClick()})}},this),this.removeDestroyed(this.onScreenWidgetIcons),e.forEach(this.widgetManager.getOnScreenOffPanelWidgets(),function(c){c.configId===
b.id&&(c.destroy(),!1===b.visible?0>this.invisibleWidgetIds.indexOf(b.id)&&this.invisibleWidgetIds.push(b.id):this.loadOnScreenWidget(b,a))},this),e.forEach(this.invisibleWidgetIds,function(c){c===b.id&&!1!==b.visible&&(this.loadOnScreenWidget(b,a),c=this.invisibleWidgetIds.indexOf(b.id),this.invisibleWidgetIds.splice(c,1))},this),b.isOnScreen||e.forEach(this.widgetManager.getControllerWidgets(),function(c){c.widgetIsControlled(b.id)&&this.reloadControllerWidget(a,c.id)},this))},destroyOnScreenWidgetIcons:function(){e.forEach(this.onScreenWidgetIcons,
function(a){a.destroy()},this);this.onScreenWidgetIcons=[]},destroyOnScreenOffPanelWidgets:function(){e.forEach(this.widgetManager.getOnScreenOffPanelWidgets(),function(a){a.isController?this._destroyControllerWidget(a):this.widgetManager.destroyWidget(a)},this)},destroyWidgetPlaceholders:function(){e.forEach(this.widgetPlaceholders,function(a){a.destroy()},this);this.widgetPlaceholders=[]},removeDestroyed:function(a){var b=[];e.forEach(a,function(c){c._destroyed&&b.push(c)});e.forEach(b,function(c){c=
a.indexOf(c);a.splice(c,1)})},_createOnScreenWidgetPlaceHolder:function(a){var b="map"===a.position.relativeTo?this.mapId:this.layoutId;var c=h.clone(a);c.position.width=40;c.position.height=40;var d=k.getPositionStyle(c.position);a=new t({index:c.placeholderIndex,configId:a.id});g.setStyle(a.domNode,d);g.place(a.domNode,b);this.widgetPlaceholders.push(a);return a},_createOnScreenWidgetIcon:function(a){var b=new u({panelManager:this.panelManager,widgetManager:this.widgetManager,widgetConfig:a,configId:a.id,
map:this.map});"map"===a.position.relativeTo?g.place(b.domNode,this.mapId):g.place(b.domNode,this.layoutId);g.setStyle(b.domNode,k.getPositionStyle({top:a.position.top,left:a.position.left,right:a.position.right,bottom:a.position.bottom,width:40,height:40}));b.startup();!this.openAtStartWidget&&a.openAtStart&&(b.switchToOpen(),this.openAtStartWidget=a.name);this.onScreenWidgetIcons.push(b);return b},reloadControllerWidget:function(a,b){var c=this.widgetManager.getWidgetById(b);if(c){var d=c.getOpenedIds(),
f=c.windowState;this._destroyControllerWidget(c);this._loadControllerWidget(a,b,d,f)}else this._loadControllerWidget(a,b)},_doPostLoad:function(){require(["dynamic-modules/postload"])},_destroyControllerWidget:function(a){e.forEach(a.getAllConfigs(),function(b){if(b.widgets)this.panelManager.destroyPanel(b.id+"_panel"),e.forEach(b.widgets,function(d){this.panelManager.destroyPanel(d.id+"_panel")},this);else{var c=this.widgetManager.getWidgetById(b.id);c&&(b.inPanel?this.panelManager.destroyPanel(c.getPanel()):
this.widgetManager.destroyWidget(c))}},this);this.widgetManager.destroyWidget(a)},_loadControllerWidget:function(a,b,c,d){b=a.getConfigElementById(b);!1!==b.visible&&this.loadOnScreenWidget(b,a).then(h.hitch(this,function(f){d&&this.widgetManager.changeWindowStateTo(f,d);c&&f.setOpenedIds(c)}))},_updatePlaceholder:function(a){e.forEach(this.widgetPlaceholders,function(b){b.setIndex(a.getConfigElementById(b.configId).placeholderIndex)},this)}});l.extend(v);l.getInstance=function(){null===m&&(m=new l);
return m};return l});