// 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/Evented dojo/_base/array dojo/_base/html dojo/_base/fx dojo/on dojo/keys dojo/sniff dojo/touch dojo/query dojo/dnd/move dijit/_WidgetBase jimu/utils".split(" "),function(w,e,x,l,b,v,h,n,y,z,r,A,B,m){var t=0;return w([B,x],{declaredClass:"jimu.dijit.Popup",baseClass:"jimu-popup",classNames:[],titleLabel:"",content:null,container:null,customZIndex:null,buttons:[],enabledButtons:[],disabledButtons:[],onClose:null,_fixedHeight:!1,autoHeight:!1,isResize:!0,
horizontalWidthRate:0,maxHeight:800,maxWidth:1024,enableMoveable:!0,hasTitle:!0,contentHasNoMargin:!1,hasOverlay:!0,moveToCenter:!0,customPosition:null,hiddenAfterInit:!1,useFocusLogic:!0,constructor:function(){this.buttons=[];this.enabledButtons=[];this.disabledButtons=[];this.pauseKeyHandles=[];this.container=jimuConfig.layoutId},focusLastActiveNode:function(){this.focusedNodeBeforeOpen&&this.useFocusLogic&&this.focusedNodeBeforeOpen.focus()},postCreate:function(){this.focusedNodeBeforeOpen=document.activeElement;
this._preProcessing();this.inherited(arguments);this._initDomNode();this._addStylesByHeightType();this._calcAndSetPosition();b.place(this.domNode,this.container);setTimeout(e.hitch(this,function(){this._calcAndSetPosition(!0,!1);this.initFocusNodes()}),50);this.isResize&&this.own(h(window,"resize",e.hitch(this,function(){this._calcAndSetPosition(!0,!0)})));this.hasOverlay&&(this.overlayNode=b.create("div",{"class":"jimu-overlay"},this.container));this.customZIndex||0===this.customZIndex?(b.setStyle(this.domNode,
"zIndex",this.customZIndex+1),this.overlayNode&&b.setStyle(this.overlayNode,"zIndex",this.customZIndex)):this._increaseZIndex();this.hiddenAfterInit&&this.hide();v.animateProperty({node:this.domNode,properties:{opacity:1},duration:200}).play();b.setAttr(this.domNode,"aria-label",window.jimuNls.common.popup);this.own(h(this.domNode,"keydown",e.hitch(this,function(a){a.keyCode===n.ESCAPE&&(this.closeBtnNode?this.closeBtnNode.focus():(this.close(),this.focusLastActiveNode()));m.preventMapNavigation(a)})))},
initFocusNodes:function(){if(this.useFocusLogic){if("string"===typeof this.content){var a="uniqMsgId_"+m.getUUID();b.setAttr(this.contentContainerNode,"id",a);b.setAttr(this.domNode,"tabindex","0");b.setAttr(this.domNode,"aria-labelledby",a)}this.firstFocusNode=this._getFirstFocusNode();this.lastFocusNode=this._getLastFocusNode();this.firstFocusNode&&(this.own(h(this.firstFocusNode,"keydown",e.hitch(this,function(c){c.shiftKey&&c.keyCode===n.TAB&&(c.preventDefault(),this.firstFocusNode.focus())}))),
this.firstFocusNode.focus());this.lastFocusNode&&this.own(h(this.lastFocusNode,"keydown",e.hitch(this,function(c){c.shiftKey||c.keyCode!==n.TAB||(c.preventDefault(),this.firstFocusNode.focus())})))}},_getFirstFocusNode:function(){var a=this.closeBtnNode;"string"===typeof this.content&&(a=this.domNode);if(!a){var c=[];this.content.domNode?c=m.getFocusNodesInDom(this.content.domNode):1===this.content.nodeType&&(c=m.getFocusNodesInDom(this.content));0<c.length?a=c[0]:this.buttons.length&&(a=this._getFirstBtn())}return a},
_getLastFocusNode:function(){var a=this._getLastBtn();if(!a)if(this.content&&"string"!==typeof this.content){var c;this.content.domNode?c=m.getFocusNodesInDom(this.content.domNode):1===this.content.nodeType&&(c=m.getFocusNodesInDom(this.content));a=0<c.length?c[c.length-1]:this.closeBtnNode}else a=this.closeBtnNode;return a},_getFirstBtn:function(){for(var a=null,c=r(".jimu-btn",this.buttonContainer),d=0;d<=c.length-1;d++)if("none"!==b.getStyle(c[d],"display")){a=c[d];break}return a},_getLastBtn:function(){for(var a=
null,c=r(".jimu-btn",this.buttonContainer),d=c.length-1;0<=d;d--)if("none"!==b.getStyle(c[d],"display")){a=c[d];break}return a},_preProcessing:function(){"number"!==typeof this.width&&(this.width=this.maxWidth);"number"===typeof this.height&&(this._fixedHeight=!0,this.autoHeight=!1);this.autoHeight&&(this.maxHeight=598)},_createTitleNode:function(){this.titleNode=b.create("div",{"class":"title"},this.domNode);this.titleLabeNode=b.create("span",{"class":"title-label jimu-float-leading",innerHTML:m.sanitizeHTML(this.titleLabel)||
"\x26nbsp"},this.titleNode);this.closeBtnNode=b.create("div",{"class":"close-btn jimu-icon jimu-icon-close jimu-float-trailing",tabindex:0,"aria-label":window.jimuNls.common.close,role:"button"},this.titleNode);var a=null;a="ontouchstart"in document?z.press:"click";this.own(h(this.closeBtnNode,a,e.hitch(this,this.close)));this.own(h(this.closeBtnNode,"keydown",e.hitch(this,function(c){c.keyCode!==n.ENTER&&c.keyCode!==n.SPACE||this.close()})))},_initDomNode:function(){for(var a=0;a<=this.classNames.length-
1;a++)b.addClass(this.domNode,this.classNames[a]);this.hasTitle&&this._createTitleNode();this.contentContainerNode=b.create("div",{"class":"content"},this.domNode);this.content&&("string"===typeof this.content?this.contentContainerNode.innerHTML=this.content:this.content.domNode?(this.content.placeAt(this.contentContainerNode),this.content.popup=this):1===this.content.nodeType&&b.place(this.content,this.contentContainerNode));this.buttonContainer=b.create("div",{"class":"button-container"},this.domNode);
0===this.buttons.length&&b.setStyle(this.buttonContainer,"display","none");for(a=0;a<=this.buttons.length-1;a++)this._createButton(this.buttons[a]),this.buttons[a].disable&&this.disableButton(a)},_limitButtonsMaxWidth:function(){var a=this.enabledButtons.length;if(0!==a){var c=b.getContentBox(this.buttonContainer),d=b.getMarginExtents(this.enabledButtons[0]),f=b.getPadBorderExtents(this.enabledButtons[0]),k=0;f=8===y("ie")?f.l+f.r:0;k=(c.w-(d.l+d.r+f)*a)/a;0<k&&(l.forEach(this.enabledButtons,e.hitch(this,
function(g){b.setStyle(g,"maxWidth",k+"px")})),l.forEach(this.disabledButtons,e.hitch(this,function(g){b.setStyle(g,"maxWidth",k+"px")})))}},_moveableNode:function(a,c){this.moveable&&(this.moveable.destroy(),this.moveable=null);var d=b.getMarginBox(this.container);d.l=d.l-a+c;d.w+=2*(a-c);this.moveable=new A.boxConstrainedMoveable(this.domNode,{box:d,handle:this.titleNode||this.contentContainerNode,within:!0});this.own(h(this.moveable,"Moving",e.hitch(this,this.onMoving)));this.own(h(this.moveable,
"MoveStop",e.hitch(this,this.onMoveStop)))},_getHeaderBox:function(){return 0===r("#header").length?{t:0,l:0,w:0,h:0}:b.getMarginBox("header")},_getFooterBox:function(){return 0===r(".footer",this.container).length?{t:0,l:0,w:0,h:0}:b.getMarginBox(r(".footer",this.container)[0])},_calcAndSetPosition:function(a,c){var d=b.getMarginBox(this.domNode);if("string"!==typeof this.container||b.byId(this.container)){var f=b.getContentBox(this.container),k=this._getHeaderBox(),g=this._getFooterBox();g=f.h-
k.h-g.h-40;var p=0,u=0;this.customPosition&&this.customPosition.height?(this.height=this.customPosition.height,u="number"===typeof this.height?this.height+"px":this.height):(this.height=this._fixedHeight?this.height>g?g:this.height:this.autoHeight?(d.h>g?g:d.h)||g-200:g>this.maxHeight?this.maxHeight:g,u=this.height+"px");this.customPosition&&this.customPosition.width?(this.width=this.customPosition.width,p="number"===typeof this.width?this.width+"px":this.width):("number"===typeof this.horizontalWidthRate&&
0<this.horizontalWidthRate?(p=b.getMarginBox(window.document.body).w*this.horizontalWidthRate,this.width=p=p>this.maxWidth?p:this.maxWidth):this.width=this.width||this.maxWidth,p=this.width+"px");var q=d=0;this.customPosition?(d="number"===typeof this.customPosition.left?this.customPosition.left+"px":this.customPosition.left,q="number"===typeof this.customPosition.top?this.customPosition.top+"px":this.customPosition.top):this.moveToCenter&&(q=(g-this.height)/2+k.h+20,q=q<k.h?k.h:q,d=(f.w-this.width)/
2+"px",q+="px");b.setStyle(this.domNode,{width:p,height:this.autoHeight?"auto":u,left:d,top:q});this.enableMoveable&&this._moveableNode(this.width,100);!this.moveToCenter&&a&&"block"===b.getStyle(this.domNode,"display")&&this.emit("popupHasInitedSuccessfully",c)}},setDomNodeStyls:function(a){b.setStyle(this.domNode,a)},setCustomPosition:function(a,c,d,f){this.width=d||this.width||this.maxWidth;this.height=f||this.height||this.maxHeight;d="number"===typeof this.width?this.width+"px":this.width;f="number"===
typeof this.height?this.height+"px":this.height;b.setStyle(this.domNode,{left:"number"===typeof a?a+"px":a,top:"number"===typeof c?c+"px":c,width:d,height:this.autoHeight?"auto":f})},_addStylesByHeightType:function(){this.autoHeight?(b.addClass(this.contentContainerNode,"content-static"),0===this.buttons.length&&b.setStyle(this.contentContainerNode,{marginBottom:"15px"})):(b.addClass(this.contentContainerNode,"content-absolute"),this.hasTitle||b.addClass(this.contentContainerNode,"no-popup-title-content-absolute"),
b.addClass(this.buttonContainer,"button-container-absolute"),0===this.buttons.length&&b.setStyle(this.contentContainerNode,{bottom:"15px"}));this.contentHasNoMargin&&b.addClass(this.contentContainerNode,"content-fill-Popup")},_increaseZIndex:function(){b.setStyle(this.domNode,"zIndex",t+200+1);this.overlayNode&&b.setStyle(this.overlayNode,"zIndex",t+200);t++},setTitleLabel:function(a){this.titleNode.innerHTML=m.stripHTML(a)},onMoving:function(a){b.setStyle(a.node,"opacity",.9)},onMoveStop:function(a){b.setStyle(a.node,
"opacity",1)},show:function(){this.overlayNode&&b.setStyle(this.overlayNode,"display","block");b.setStyle(this.domNode,"display","block")},hide:function(){this.overlayNode&&b.setStyle(this.overlayNode,"display","none");b.setStyle(this.domNode,"display","none")},close:function(){if(!this.onClose||!1!==this.onClose()){var a=this.domNode.parentNode,c=e.clone(this.domNode);b.setStyle(this.domNode,"display","none");this.overlayNode&&b.destroy(this.overlayNode);this.destroy();this.moveable&&this.moveable.destroy();
b.place(c,a);v.animateProperty({node:c,properties:{opacity:0},duration:200,onEnd:function(){b.destroy(c)}}).play();this.focusLastActiveNode();window.currentMsgPopup=null}},addButton:function(a){this._createButton(a)},_createButton:function(a){var c=" ";a.classNames&&0<a.classNames.length&&"function"===typeof a.classNames.join&&(c+=a.classNames.join(" "));var d=b.create("div",{"class":"jimu-btn jimu-popup-action-btn jimu-float-trailing jimu-trailing-margin1 "+c,innerHTML:a.label,tabindex:0,role:"button",
title:a.title||a.label},this.buttonContainer);this.enabledButtons.push(d);c=b.create("div",{"class":"jimu-btn jimu-state-disabled jimu-float-trailing jimu-trailing-margin1 "+c,title:a.title||a.label,innerHTML:a.label,tabindex:0,role:"button","aria-disabled":"true",style:{display:"none"}},this.buttonContainer);this.disabledButtons.push(c);this.own(h(d,"click",e.hitch(this,function(f){if(a.onClick)a.onClick(f);else this.close()})));this.own(h(d,"keydown",e.hitch(this,function(f){if(f.keyCode===n.ENTER||
f.keyCode===n.SPACE)if(a.onClick)a.onClick(f);else this.close()})))},setButtonProps:function(a,c){"number"===typeof a&&isFinite(a)||(c=a,a=0);if(c&&0!==this.enabledButtons.length)for(var d in c)"title"===d?(b.setAttr(this.enabledButtons[a],"title",c[d]),b.setAttr(this.disabledButtons[a],"title",c[d])):"label"===d&&(b.setProp(this.enabledButtons[a],"innerHTML",c[d]),b.setProp(this.disabledButtons[a],"innerHTML",c[d]))},enableButton:function(a){"number"===typeof a&&isFinite(a)&&a<this.enabledButtons.length?
(b.setStyle(this.enabledButtons[a],"display","inline-block"),b.setStyle(this.disabledButtons[a],"display","none")):(l.forEach(this.enabledButtons[a],e.hitch(this,function(c){b.setStyle(c,"display","inline-block")})),l.forEach(this.disabledButtons[a],e.hitch(this,function(c){b.setStyle(c,"display","none")})))},disableButton:function(a){"number"===typeof a&&isFinite(a)&&a<this.disabledButtons.length?(b.setStyle(this.disabledButtons[a],"display","inline-block"),b.setStyle(this.enabledButtons[a],"display",
"none")):(l.forEach(this.disabledButtons,e.hitch(this,function(c){b.setStyle(c,"display","inline-block")})),l.forEach(this.enabledButtons,e.hitch(this,function(c){b.setStyle(c,"display","none")})))},showButton:function(a){this.enableButton(a)},hideButton:function(a){"number"===typeof a&&isFinite(a)&&a<this.disabledButtons.length?(b.setStyle(this.disabledButtons[a],"display","none"),b.setStyle(this.enabledButtons[a],"display","none")):(l.forEach(this.disabledButtons,e.hitch(this,function(c){b.setStyle(c,
"display","none")})),l.forEach(this.enabledButtons,e.hitch(this,function(c){b.setStyle(c,"display","none")})))},resize:function(a){a&&(this.width=a.w,this.height=a.h);this._calcAndSetPosition();this.content&&this.content.domNode&&this.content.resize&&this.content.resize()}})});