// 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 dijit/_TemplatedMixin dojo/_base/lang dojo/_base/html dojo/on dojo/keys dojo/_base/Color dijit/TooltipDialog dijit/popup jimu/dijit/ColorSelector jimu/utils".split(" "),function(m,n,p,g,b,h,k,e,q,l,r,t){return m([n,p],{baseClass:"jimu-color-picker",declaredClass:"jimu.dijit.ColorPicker",templateString:'\x3cdiv role\x3d"button" tabindex\x3d"0"data-dojo-attach-event\x3d"onclick:_domNodeClick,onkeydown:_domNodeKeydown" aria-pressed\x3d"false"\x3e\x3c/div\x3e',
_isTooltipDialogOpened:!1,color:null,showHex:!0,showHsv:!0,showRgb:!0,ensureMode:!1,showLabel:!1,postMixInProperties:function(){this.nls=window.jimuNls.common},postCreate:function(){this.inherited(arguments);this.color?this.color instanceof e||(this.color=new e(this.color)):this.color=new e("#ccc");b.setStyle(this.domNode,"backgroundColor",this.color.toHex());this.showLabel&&this._changeLabel(this.color);this._createTooltipDialog(this.domNode);this._hideTooltipDialog()},destroy:function(){l.close(this.tooltipDialog);
this.picker.destroy();this.tooltipDialog.destroy();this.inherited(arguments)},isPartOfPopup:function(a){var f=this.tooltipDialog.domNode;return a===f||b.isDescendant(a,f)},hideTooltipDialog:function(){this._hideTooltipDialog()},_showTooltipDialog:function(){l.open({parent:this.getParent(),popup:this.tooltipDialog,around:this.domNode});this._isTooltipDialogOpened=!0;this.picker.cursorNode.focus()},_hideTooltipDialog:function(){this._isTooltipDialogOpened=!1;this.onClose();l.close(this.tooltipDialog)},
_createTooltipDialog:function(){var a=b.create("div");this.tooltipDialog=new q({content:a});b.addClass(this.tooltipDialog.domNode,"jimu-color-picker-dialog");this.own(h(this.tooltipDialog.domNode,"keydown",g.hitch(this,function(c){c.keyCode===k.ESCAPE&&(this._hideTooltipDialog(),this.domNode.focus(),b.setAttr(this.domNode,"aria-pressed","false"))})));var f=new r({showHex:this.showHex,showRgb:this.showRgb,showHsv:this.showHsv,value:this.color.toHex(),onChange:g.hitch(this,function(c){this.ensureMode||
(c=new e(c),this.setColor(c))})});f.placeAt(a);f.startup();if(this.ensureMode){var d=b.create("div",{"class":"jimu-btn jimu-btn-vacation jimu-float-trailing",title:this.nls.cancel,innerHTML:this.nls.cancel},a);this.own(h(d,"click",g.hitch(this,function(){this._hideTooltipDialog()})));"undefined"===typeof this.showOk&&(d=b.create("div",{"class":"jimu-btn jimu-float-trailing ok",title:this.nls.ok,innerHTML:this.nls.ok},a),this.own(h(d,"click",g.hitch(this,function(){var c=this.picker.get("value");this.setColor(new e(c));
this._hideTooltipDialog()}))));a=b.create("div",{"class":"jimu-btn jimu-float-trailing",title:this.nls.apply,innerHTML:this.nls.apply},a);this.own(h(a,"click",g.hitch(this,function(){var c=this.picker.get("value");this.setColor(new e(c))})))}this.own(h(document.body,"click",g.hitch(this,function(c){this.isPartOfPopup(c.target||c.srcElement)||this._hideTooltipDialog()})));this.picker=f},_domNodeClick:function(a){a.stopPropagation();a.preventDefault();this._isTooltipDialogOpened?(this._hideTooltipDialog(),
b.setAttr(this.domNode,"aria-pressed","false")):(this._showTooltipDialog(),b.setAttr(this.domNode,"aria-pressed","true"))},_domNodeKeydown:function(a){a.keyCode!==k.ENTER&&a.keyCode!==k.SPACE||this._domNodeClick(a)},setColor:function(a,f){if(a instanceof e){var d=this.color,c="";d&&(c=d.toHex());d=a.toHex();this.color=a;b.setStyle(this.domNode,"backgroundColor",d);if(c!==d&&(this.picker.set("value",d),!1!==f))this.onChange(new e(d))}},getColor:function(){return this.color},_changeLabel:function(a){b.empty(this.domNode);
b.create("span",{innerHTML:a.toHex(),className:"color-label",style:{color:t.invertColor(a.toHex())}},this.domNode)},onChange:function(a){this.showLabel&&this._changeLabel(a)},onClose:function(){},getPopup:function(){return this.tooltipDialog||null},setLabel:function(a){b.empty(this.domNode);b.create("span",{innerHTML:a||"",className:"text-label"},this.domNode)},isTooltipDialogOpened:function(){return this._isTooltipDialogOpened}})});