// 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 dojo/dom-construct dojo/query dijit/_WidgetBase dijit/_TemplatedMixin jimu/dijit/ViewStack jimu/utils".split(" "),function(t,k,u,g,l,h,m,n,v,w,x,r){return t([v,w],{baseClass:"jimu-header-more-popup",templateString:'\x3cdiv\x3e\x3cdiv class\x3d"close" tabindex\x3d"0" data-dojo-attach-point\x3d"closeNode"\x3e\x3c/div\x3e\x3cdiv class\x3d"pages" data-dojo-attach-point\x3d"pagesNode"\x3e\x3c/div\x3e\x3cdiv class\x3d"points jimu-corner-bottom"\x3e\x3cdiv class\x3d"points-inner"data-dojo-attach-point\x3d"pointsNode"\x3e\x3c/div\x3e\x3c/div\x3e\x3c/div\x3e',
margin:4,postCreate:function(){this.nodes=[];this.pages=[];this.createCloseBtn();this.own(l(this.domNode,"keydown",k.hitch(this,function(a){g.hasClass(a.target,"close-btn")||a.keyCode!==h.ESCAPE||this.closeNode.focus()})))},startup:function(){this.viewStack=new x({views:[],viewType:"dom"},this.pagesNode);this.viewStack.startup();this.resize();this.nodes.length&&this.nodes[0].focus()},resize:function(){var a=this._calculateGridParam();if(null!==a){g.setStyle(this.domNode,r.getPositionStyle(a.position));
this.nodeWidth=a.cellSize-this.margin;this.oldGridParam&&this.oldGridParam.rows===a.rows&&this.oldGridParam.cols===a.cols||(this.clearPages(),this.createPages(a));this.nodes.forEach(k.hitch(this,function(b,c){this.setItemNodePosition(b,c,a)}));this.oldGridParam=a;var d=n("div.close",this.domNode)[0];g.setStyle(d,{width:.25*this.nodeWidth+"px",height:.25*this.nodeWidth+"px"})}else this.oldGridParam=null,g.setStyle(this.domNode,r.getPositionStyle({left:0,top:0,width:0,height:0,zIndex:111})),this.nodeWidth=
0},setItemNodePosition:function(a,d,b){var c=48,e=16;var f=0===d%b.cols?0:this.margin/2;var p=d%(b.rows*b.cols)<b.cols?0:this.margin/2;d={};"number"===typeof this.nodeWidth&&(d.width=this.nodeWidth+"px",d.height=this.nodeWidth+"px");"number"===typeof f&&(window.isRTL?d.marginRight=f+"px":d.marginLeft=f+"px");"number"===typeof p&&(d.marginTop=p+"px");if(f=n("img",a)[0])b.iconScaled&&(c*=this.nodeWidth/120),g.setStyle(f,{width:c+"px",height:c+"px"});if(c=n("div.node-label",a)[0])b.showLabel?(b.iconScaled&&
(e*=this.nodeWidth/120),g.setStyle(c,{"font-size":e+"px",display:"block"})):g.setStyle(c,{"font-size":e+"px",display:"none"});g.setStyle(a,d)},clearPages:function(){u.forEach(this.pages,function(a){this.viewStack.removeView(a.pageNode)},this);m.empty(this.pointsNode);this.pages=[];this.nodes=[]},createPages:function(a){var d;var b=Math.ceil(this.items.length/(a.rows*a.cols));for(d=0;d<b;d++){var c=m.create("div",{"class":"page"});this.createPageItems(d,c,a);this.viewStack.addView(c);if(1<b){var e=
d===b-1;var f=m.create("div",{"class":"point",role:"button",tabindex:0},this.pointsNode);this.own(l(f,"click",k.hitch(this,this._onPageNodeClick,d)));this.own(l(f,"keydown",k.hitch(this,function(p,y,q){q.keyCode===h.ENTER||q.keyCode===h.SPACE?(this._onPageNodeClick(p),n(".page.view",this.viewStack.domNode)[p].children[0].focus()):y&&!q.shiftKey&&q.keyCode===h.TAB&&q.preventDefault()},d,e)))}this.pages.push({pageNode:c,pointNode:f})}0<this.viewStack.views.length&&this._selectPage(0)},_onPageNodeClick:function(a){this._selectPage(a)},
_selectPage:function(a){1<this.pages.length&&(n(".point",this.domNode).removeClass("point-selected"),g.addClass(this.pages[a].pointNode,"point-selected"));this.viewStack.switchView(this.pages[a].pageNode)},createPageItems:function(a,d,b){var c=this.items.length;var e=b.rows*b.cols;b=(a+1)*e;var f=b-c;b=Math.min(b,c);for(a*=e;a<b;a++)this.createItemNode(a,d);for(a=c;a<c+f;a++)this.createEmptyItemNode(d)},createItemNode:function(a,d){a=this.items[a];var b=m.create("div",{"class":"icon-node jimu-float-leading jimu-main-background",
title:a.label,settingId:a.id,"data-widget-name":a.name,role:"button",tabindex:0},d);d=m.create("img",{src:a.icon},b);window.isRTL&&a.mirrorIconForRTL&&g.addClass(d,"jimu-flipx");m.create("div",{"class":"node-label",title:a.label,innerHTML:r.stripHTML(a.label)},b);b.config=a;this.own(l(b,"click",k.hitch(this,function(){this.onNodeClicked(b)})));this.own(l(b,"keydown",k.hitch(this,function(c){if(c.keyCode===h.ENTER||c.keyCode===h.SPACE)this.onNodeClicked(b)})));this.nodes.push(b)},createEmptyItemNode:function(a){a=
m.create("div",{"class":"icon-node jimu-float-leading jimu-main-background",tabindex:0},a);this.own(l(a,"focus",k.hitch(this,function(d){r.isInNavMode()&&(1===this.viewStack.domNode.children.length?d.target.parentNode.children[0].focus():n(".point-selected",this.pointsNode)[0].previousSibling.focus())})));this.nodes.push(a);return a},createCloseBtn:function(){m.create("div",{role:"button","class":"close-inner jimu-main-background"},this.closeNode);this.own(l(this.closeNode,"click",k.hitch(this,function(){this.hide()})));
this.own(l(this.closeNode,"keydown",k.hitch(this,function(a){a.keyCode===h.ENTER||a.keyCode===h.SPACE||a.keyCode===h.ESCAPE?this.hide():a.shiftKey&&a.keyCode===h.TAB&&a.preventDefault()})));return this.closeNode},hide:function(){g.setStyle(this.domNode,"display","none")},show:function(){g.setStyle(this.domNode,"display","block")},onNodeClicked:function(a){this.hide()},openNodebyId:function(a){for(var d=0,b=this.nodes.length;d<b;d++){var c=this.nodes[d];if(a&&a===g.getAttr(c,"settingId"))return this.onNodeClicked(c),
c}},_calculateGridParam:function(){var a=!1,d=!0;var b=g.getContentBox(jimuConfig.mapId);var c=Math.min(b.w,b.h)-40;if(360<=c)var e=120;else{e=Math.floor(c/3);if(10>e)return null;a=!0;80>e&&(d=!1)}c=Math.floor((b.h-40)/e);var f=Math.floor((b.w-40)/e);c=4<c?4:c;c=3>c?3:c;f=3>c?3:4<f?4:f;return{rows:c,cols:f,cellSize:e,iconScaled:a,showLabel:d,position:{top:(b.h-e*c)/2,bottom:(b.h-e*c)/2,left:(b.w-e*f)/2,right:(b.w-e*f)/2,width:e*f-this.margin*(f-1)/2,height:e*c-this.margin*(c-1)/2,zIndex:111}}}})});