// 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/aspect dojo/Evented dojo/on dojo/keys dojo/query dojo/_base/html dojo/_base/lang dojo/_base/array dojo/_base/declare dijit/_WidgetBase jimu/filterUtils jimu/utils jimu/dijit/Popup jimu/dijit/formSelect jimu/dijit/dateTimePicker".split(" "),function(l,n,f,m,p,e,d,q,r,t,g,k,u,v,w){return r([t,n],{virtualDates:null,customId:null,postMixInProperties:function(){this.inherited(arguments);this.nls=window.jimuNls.filterBuilder},postCreate:function(){this.inherited(arguments);e.addClass(this.domNode,
"jimu-date-value-selector");this.dateTypeSelect=new v({"aria-label":this.prompt});e.addClass(this.dateTypeSelect.domNode,"date-type-select");e.addClass(this.dateTypeSelect.domNode,"restrict-select-width");this.dateTypeSelect.placeAt(this.domNode);this.own(f(this.dateTypeSelect,"change",d.hitch(this,function(){this._onDateTypeSelectChanged()})));this.virtualDates&&0<this.virtualDates.length||(this.virtualDates=[g.VIRTUAL_DATE_TODAY,g.VIRTUAL_DATE_YESTERDAY,g.VIRTUAL_DATE_TOMORROW],this.runtime&&this.virtualDates.unshift(g.VIRTUAL_DATE_CUSTOM));
this.dateTypeSelect.addOption({value:"",label:"\x26nbsp;"});(!this.runtime||this.runtime&&0<=this.virtualDates.indexOf(g.VIRTUAL_DATE_CUSTOM))&&this.dateTypeSelect.addOption({value:"custom",label:this.nls.custom});q.map(this.virtualDates,d.hitch(this,function(b){if("custom"!==b){var a={value:b,label:b};switch(b){case g.VIRTUAL_DATE_TODAY:a.label=this.nls.today;break;case g.VIRTUAL_DATE_YESTERDAY:a.label=this.nls.yesterday;break;case g.VIRTUAL_DATE_TOMORROW:a.label=this.nls.tomorrow}this.dateTypeSelect.addOption(a)}}));
this.dateTypeSelect.startup();this.own(f(e.byId("main-page"),"click",d.hitch(this,function(){this.hideDateTimePopup()})));this.own(l.before(this.dateTypeSelect,"openDropDown",d.hitch(this,function(){this.hideDateTimePopup();"custom"===this.dateTypeSelect.getValue()&&this.dateTimeObj&&this.dateTimeObj.value&&(this.dateTypeSelect.textDirNode.innerText=this.dateTimeObj.value);"custom"!==this.dateTypeSelect.getValue()&&this.dateTimePopup&&this.dateTimePopup.hide()})));this.own(l.after(this.dateTypeSelect,
"closeDropDown",d.hitch(this,function(){this.customId||e.setAttr(this.dateTypeSelect,"aria-label",this.dateTypeSelect.textDirNode.innerText);this.dateTypeSelect.textDirNode.title="";setTimeout(d.hitch(this,function(){"custom"===this.dateTypeSelect.getValue()&&this.dateTimeObj&&this.dateTimeObj.value&&this.dateTypeSelect.textDirNode&&(this.dateTypeSelect.textDirNode.innerText=this.dateTimeObj.value,this.dateTypeSelect.textDirNode.title=this.dateTimeObj.value);this.dateTimePopup&&this.dateTimePopup.domNode&&
"block"===e.getStyle(this.dateTimePopup.domNode,"display")&&this.dateTimePicker&&this.dateTimePicker.calendar&&this.dateTimePicker.calendar.focus()}),200)})));this.own(l.after(this.dateTypeSelect.dropDown,"onItemClick",d.hitch(this,function(b){b&&"custom"===b.option.value&&this.showDateTimePopup()}),!0));this.popupInfo&&this.popupInfo.fieldInfos&&(this.fieldInfo=this.popupInfo.fieldInfos.filter(d.hitch(this,function(b){return b.fieldName===this._fieldInfo.name}))[0])},hideDateTimePopup:function(){this.dateTimePopup&&
this.dateTimePopup.domNode&&"block"===e.getStyle(this.dateTimePopup.domNode,"display")&&(this.dateTimePicker&&!0===this.dateTimePopupClick?this.dateTimePopupClick=!1:this.dateTimePopup.hide())},getDijits:function(){return[]},setValueObject:function(b){if(b.virtualDate&&"custom"!==b.virtualDate)this.dateTypeSelect.set("value",b.virtualDate,!1),this.customId||e.setAttr(this.dateTypeSelect,"aria-label",b.virtualDate);else if(this.dateTypeSelect.set("value","custom",!1),b.value){var a=k.getDateByDateTimeStr(b.value),
c=k.localizeDateTimeByFieldInfo(a,this.fieldInfo,b.enableTime,b.timeAccuracy);this.dateTimeObj={date:a,value:c};this.dateTypeSelect.textDirNode.innerText=c;this.dateTypeSelect.textDirNode.title=c;this.enableTime=b.enableTime;this.timeAccuracy=b.timeAccuracy;this.customId||e.setAttr(this.dateTypeSelect,"aria-label",this.dateTypeSelect.textDirNode.innerText)}},getValueObject:function(){return this.isValidValue()?this.tryGetValueObject():null},tryGetValueObject:function(){if(this.isInvalidValue())return null;
var b={value:null,virtualDate:""},a=this.dateTypeSelect.get("value"),c=null;"custom"===a?(c=this.dateTimeObj.date,b.value=c?k.getDateTimeStr(c,!0):null,b.virtualDate="",b.enableTime=this.enableTime?this.enableTime:!1,b.timeAccuracy=this.timeAccuracy?this.timeAccuracy:""):(c=g.getRealDateByVirtualDate(a),b.virtualDate=a,c?b.value=k.getDateTimeStr(c):b=null);return b},setRequired:function(){},getStatus:function(){return"custom"===this.dateTypeSelect.get("value")?this.dateTimePicker?this._getStatusForDijit(this.dateTimePicker):
this.dateTimeObj?1:0:""===this.dateTypeSelect.get("value")?0:1},_getStatusForDijit:function(b){return b.validate()?b.get("DisplayedValue")?1:0:-1},isInvalidValue:function(){return 0>this.getStatus()},isEmptyValue:function(){return 0===this.getStatus()},isValidValue:function(){return 0<this.getStatus()},_onDateTypeSelectChanged:function(){"dateTime"===this.dateTypeSelect.get("value")&&this.showDateTimePopup();this.emit("change",this.dateTypeSelect.get("value"))},showDateTimePopup:function(){if(this.dateTimePopup)this.resize(),
this.dateTimePicker.reset(),this.dateTimePopup.show();else{this.dateTimeObj||(this.dateTimeObj={date:null});this.dateTimePicker=new w({runtime:this.runtime,value:this.dateTimeObj.date,fieldInfo:this.fieldInfo,enableTime:this.enableTime,timeAccuracy:this.timeAccuracy});this.own(f(this.dateTimePicker,"created",d.hitch(this,function(a){this.dateTypeSelect.textDirNode.innerText=a.value;this.dateTypeSelect.textDirNode.title=a.value;this.dateTimeObj=a})));this.own(f(this.dateTimePicker,"timeChange",d.hitch(this,
function(a){a&&(this.dateTypeSelect.textDirNode.innerText=a.value,this.dateTypeSelect.textDirNode.title=a.value,this.enableTime=a.enableTime,this.timeAccuracy=a.timeAccuracy,this.dateTimeObj=a,this.emit("change"))})));this.own(f(this.dateTimePicker,"timeStatusChanged",d.hitch(this,function(){this.popupH=this.enableTime?353:309})));this.own(f(this.dateTimePicker,"close",d.hitch(this,function(){this.dateTimePopup.hide();this.dateTypeSelect.focus()})));this.runtime?this._isOnlyShowDate()?(this.popupH=
265,this.own(f(this.dateTimePicker,"calendarChange",d.hitch(this,function(a){a&&this.dateTypeSelect.textDirNode.innerText!==a.value&&(this.dateTypeSelect.textDirNode.innerText=a.value,this.dateTypeSelect.textDirNode.title=a.value,this.enableTime=a.enableTime,this.timeAccuracy=a.timeAccuracy,this.dateTimeObj=a,this.emit("change"))})))):this.popupH=320:this.popupH=this.enableTime?353:309;var b=this._calculatePopup();this.dateTimePopup=new u({width:this.popupW,autoHeight:!0,classNames:["dijitCalendarPopup",
"jimu-popup-date-time-picker"],content:this.dateTimePicker.domNode,enableMoveable:!1,hasTitle:!1,hasOverlay:!1,contentHasNoMargin:!0,moveToCenter:!1,customPosition:{left:b.left,top:b.top},useFocusLogic:!1,onClose:d.hitch(this,function(){this.dateTimePopup.hide();return!1}),buttons:[]});this._isOnlyShowDate()&&e.setStyle(this.dateTimePopup.contentContainerNode,{marginBottom:"-3px"});this.own(f(this.dateTimePopup.domNode,"click",d.hitch(this,function(){this.dateTimePopupClick=!0})));this.own(f(this.dateTimePopup.domNode,
"keydown",d.hitch(this,function(a){a.keyCode===m.ESCAPE?(this.dateTimePopup.hide(),this.dateTypeSelect.focus()):this.runtime&&a.keyCode===m.TAB&&(a.preventDefault(),this._isOnlyShowDate()||(e.hasClass(a.target,"dijitCalendarSelectedDate")?this.dateTimePicker.timeTextBox.focusNode:this.dateTimePicker.calendar).focus())})))}},_getLastBtnFromDTPopup:function(){for(var b=null,a=p(".jimu-btn",this.dateTimePopup.buttonContainer),c=a.length-1;0<=c;c--)if("none"!==e.getStyle(a[c],"display")){b=a[c];break}return b},
_isOnlyShowDate:function(){return this.runtime&&!this.enableTime?!0:!1},_calculatePopup:function(){var b=e.getStyle(this.domNode,"width");this.popupW=210<b?b:210;var a=e.position(this.domNode),c=e.position(document.body).h,h=a.y+30;c-h<this.popupH&&(h=a.y-this.popupH,h=0<h?h:(c-this.popupH)/2);c=e.position(document.body).w;a.x+this.popupW>c&&(a.x-=this.popupW-b);return{left:a.x,top:h-1}},resize:function(){var b=this._calculatePopup();this.dateTimePopup.setCustomPosition(b.left,b.top,this.popupW,this.popupH)},
destroy:function(){this.dateTimePopup&&(this.dateTimePopup.onClose=d.hitch(this,function(){return!0}),this.dateTimePopup.close())}})});