// 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 dojo/on dojo/keys dijit/Tooltip dijit/_WidgetBase ./utils".split(" "),function(m,b,n,d,f,g,p,q,k){return m(q,{"class":"jimu-widget-onscreen-icon",postCreate:function(){this.inherited(arguments);this.iconNode=d.create("img",{src:this.widgetConfig.icon,alt:this.widgetConfig.label},this.domNode);window.isRTL&&this.widgetConfig.mirrorIconForRTL&&d.addClass(this.iconNode,"jimu-flipx");d.setAttr(this.domNode,"title",this.widgetConfig.label);
d.setAttr(this.domNode,"data-widget-name",this.widgetConfig.name);d.setAttr(this.domNode,"tabindex",this.widgetConfig.tabIndex?this.widgetConfig.tabIndex:this.widgetConfig.tabIndexJimu);d.setAttr(this.domNode,"role","button");this.own(f(this.domNode,"click",b.hitch(this,function(){this.onClick()})));this.own(f(this.domNode,"keydown",b.hitch(this,function(a){if(a.keyCode===g.ENTER||a.keyCode===g.SPACE)this.onClick();else a.keyCode===g.ESCAPE&&this.map.container.focus()})));k.addTooltipByDomNode(p,
this.domNode,this.widgetConfig.label);this.position=b.clone(this.widgetConfig.position);"map"===this.widgetConfig.position.relativeTo&&this.own(f(this.map,"resize",b.hitch(this,function(){var a=b.clone(this.position);delete a.width;delete a.height;this.panel&&this.panel.setPosition(a)})));this.state="closed"},startup:function(){this.inherited(arguments)},onClick:function(){"closed"===this.state?this.switchToOpen():this.switchToClose()},moveTo:function(a){var c={left:"auto",right:"auto",bottom:"auto",
top:"auto",width:"auto",height:"auto"};c=b.mixin(c,k.getPositionStyle(a));delete c.width;delete c.height;d.setStyle(this.domNode,c);this.position=b.clone(a);this.widgetConfig&&this.widgetConfig.panel&&(this.widgetConfig.panel.position=b.clone(a),this.widgetConfig.position=b.clone(a));this.panel&&this.panel.setPosition(b.clone(a));this.widget&&this.widget.setPosition(this.getOffPanelWidgetPosition(this.widget))},destroy:function(){this.panel?this.panelManager.destroyPanel(this.panel):this.widget&&
this.widgetManager.destroyWidget(this.widget);this.inherited(arguments)},switchToOpen:function(){this.state="opened";this.panelManager.closeAllPanelsInGroup(this.widgetConfig.gid);n.forEach(this.widgetManager.getOnScreenOffPanelWidgets(),function(a){a.closeable&&this.widgetManager.closeWidget(a)},this);d.addClass(this.domNode,"jimu-state-selected");this._showLoading();!1===this.widgetConfig.inPanel?this.widgetManager.loadWidget(this.widgetConfig).then(b.hitch(this,function(a){this.widget=a;a.setPosition(this.getOffPanelWidgetPosition(a));
this.widgetManager.openWidget(a);this.own(f(a,"close",b.hitch(this,function(){this.switchToClose();this.iconNode.parentNode.focus()})));this._hideLoading()})):this.panelManager.showPanel(b.clone(this.widgetConfig)).then(b.hitch(this,function(a){this.panel=a;this.own(f(a,"close",b.hitch(this,function(){this.switchToClose();this.iconNode.parentNode.focus()})));this.own(f(a.closeNode,"keydown",b.hitch(this,function(c){c.keyCode===g.ESCAPE&&(c.stopPropagation(),this.iconNode.parentNode.focus())})));this._hideLoading()}))},
switchToClose:function(){this.state="closed";d.removeClass(this.domNode,"jimu-state-selected");!1===this.widgetConfig.inPanel?this.widgetManager.closeWidget(this.widget):this.panelManager.closePanel(this.panel)},getOffPanelWidgetPosition:function(a){var c={relativeTo:a.position.relativeTo},e=d.getMarginBox(this.domNode);a=this.widgetManager.getWidgetMarginBox(a);var h=d.getMarginBox("map"===c.relativeTo?this.map.id:jimuConfig.layoutId),l=e.t+e.h+1;l+a.h>h.h?c.bottom=h.h-e.t+1:c.top=l;window.isRTL?
c.right=0>e.l+e.w-a.w?0:e.l+e.w-a.w:e.l+a.w>h.w?c.right=0:c.left=e.l;return c},_showLoading:function(){d.setAttr(this.iconNode,"src",require.toUrl("jimu")+"/images/loading_circle.gif")},_hideLoading:function(){d.setAttr(this.iconNode,"src",this.widgetConfig.icon)}})});