// 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 dijit/_WidgetBase dojo/_base/lang dojo/_base/array dojo/_base/html dojo/query dojo/on dijit/focus dojo/keys dojo/Evented ../utils".split(" "),function(p,q,h,r,e,l,k,t,u,v,m){return p([q,v],{baseClass:"jimu-dropmenu",declaredClass:"jimu.dijit.DropMenu",focusNodeWhenLeave:null,constructor:function(){this.state="closed"},postCreate:function(){this.btnNode=e.create("div",{"class":"popup-menu-button"},this.domNode);this.own(k(this.btnNode,"click",h.hitch(this,this._onBtnClick)));
this.box||(this.box=this.domNode.parentNode);this.own(k(this.box,"click",h.hitch(this,function(){this.dropMenuNode&&this.closeDropMenu()})))},_onBtnClick:function(a){a.stopPropagation();this.dropMenuNode||this._createDropMenuNode();"closed"===this.state?this.openDropMenu():this.closeDropMenu()},_createDropMenuNode:function(){this.dropMenuNode=e.create("div",{"class":"drop-menu",style:{display:"none"}},this.domNode);this.items||(this.items=[]);r.forEach(this.items,function(a){if(a.key&&"separator"===
a.key)e.create("hr",{"class":"menu-item-identification menu-item-line",itemId:a.key},this.dropMenuNode);else if(a.key){var d=e.create("div",{"class":"menu-item-identification menu-item",tabindex:"0",itemId:a.key,role:"button",innerHTML:m.sanitizeHTML(a.label)},this.dropMenuNode);this.own(k(d,"click",h.hitch(this,function(b){this.selectItem(a,b)})));this.own(k(d,"keydown",h.hitch(this,function(b){if(b.keyCode===u.ENTER){b.stopPropagation();b.preventDefault();var f=l("a",d)[0];f?(b=document.createEvent("MouseEvents"),
b.initEvent("click",!0,!0),f.dispatchEvent(b)):this.selectItem(a,b)}})))}},this);this.focusNodeWhenLeave||(this.focusNodeWhenLeave=this.domNode.parentNode)},_getDropMenuPosition:function(){var a=e.getContentBox(this.box),d=e.getMarginBox(this.domNode),b=e.getMarginBox(this.btnNode),f=e.getMarginBox(this.dropMenuNode),c={};c.l=d.l;c.t=d.t+b.h;if(c.t+f.h>a.h){var n=d.t;var g=a.h-d.t-b.h;g=Math.max(n,g);g===n&&(c.t=0-f.h)}c.l+f.w>a.w&&(f=d.l,a=a.w-d.l-b.w,g=Math.max(f,a),g===f&&(c.l="",c.r=0));c.left=
c.l;c.top=c.t;c.right=c.r;return c},getMenuItemNodeByItemKey:function(a){var d;l(".menu-item",this.dropMenuNode).some(function(b){return e.getAttr(b,"itemId")===a?(d=b,!0):!1},this);return d},selectItem:function(a){this.closeDropMenu();this.emit("onMenuClick",a)},openDropMenu:function(){this.state="opened";e.setStyle(this.dropMenuNode,"display","");e.setStyle(this.dropMenuNode,m.getPositionStyle(this._getDropMenuPosition()));this.emit("onOpenMenu")},closeDropMenu:function(){"opened"===this.state&&
t.focus(this.focusNodeWhenLeave);this.state="closed";e.setStyle(this.dropMenuNode,"display","none");this.emit("onCloseMenu")}})});