// 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/Evented dojo/_base/lang dojo/_base/array dojo/dom-construct dojo/dom-class dojo/on dojo/keys dojo/string dojo/dom-attr dojo/mouse ./presetUtils ./RelativeDates dijit/_TemplatedMixin jimu/BaseWidgetSetting dijit/form/FilteringSelect dojo/store/Memory dijit/form/ValidationTextBox dijit/form/NumberTextBox dijit/form/SimpleTextarea esri/urlUtils jimu/dijit/Message jimu/utils".split(" "),function(y,z,g,u,f,A,h,q,r,m,B,t,v,C,D,E,F,w,G,H,I,x,J){return y([D,z,C],{baseClass:"jimu-widget-smartEditor-setting-preset",
tooltipContents:{},hasAtLeastOneGroupInDisplay:!1,enableUsePresetValueCheckBox:!1,postCreate:function(){this.inherited(arguments);this.enableUsePresetValueCheckBox=this.hasAtLeastOneGroupInDisplay=!1;this.tooltipContents={};this.presetContainer=f.create("div",{"class":"esriCTPresetContent"},this.parentNode);this._createPresetContents()},_fetchUrlParameters:function(){var a=I.urlToObject(document.location.href);if(a.query)var b=a.query;return b},_createPresetContents:function(){var a=this._fetchUrlParameters();
for(var b=0;b<this.presetOrder.length;b++){var c=this.presetOrder[b];var d=this._isGroupNameFound(a,c);d=a&&d.isConfiguredGroupName?this._createPresetContentDOM(this._configuredPresetInfos[c],a[d.urlParamKey]):this._createPresetContentDOM(this._configuredPresetInfos[c]);this._configuredPresetInfos[c].hideInPresetDisplay?A.add(d,"esriCTHidden"):this.hasAtLeastOneGroupInDisplay=!0;this._createTooltipContent(this._configuredPresetInfos[c])}},_hasFieldsInPresetGroup:function(a){var b=!1,c;for(c in a.appliedOn)if(0<
a.appliedOn[c].length){b=!0;break}return b},_isGroupNameFound:function(a,b){var c=!1,d;a&&u.forEach(Object.keys(a),g.hitch(this,function(e){if(e.toLowerCase()===b.toLowerCase())return c=!0,d=e,!0}));return{isConfiguredGroupName:c,urlParamKey:d}},_createPresetContentDOM:function(a,b){var c=f.create("tr"),d=f.create("td"),e=f.create("div",{"class":"esriCTGroupInfoIcon","aria-label":r.substitute(this.nls.groupInfoLabel,{groupName:a.name}),tabindex:"0",role:"button"},d),k=f.create("span",{innerHTML:a.name,
"class":"ee-atiLabel"},d);m.set(k,"groupName",a.name);m.set(e,"groupName",a.name);this.own(h(e,"click",g.hitch(this,function(l){l=m.get(l.currentTarget,"groupName");x({message:this.tooltipContents[l].innerHTML})})));this.own(h(e,"keydown",g.hitch(this,function(l){if(l.keyCode===q.ENTER||l.keyCode===q.SPACE)l=m.get(l.currentTarget,"groupName"),x({message:this.tooltipContents[l].innerHTML})})));f.place(d,c);d=f.create("td",{"class":"preset-value-editable"},c);if(a.showOnlyDomainFields)a=this._createDomainContentNode(a,
d),void 0!==b&&a.set("value",b);else switch(a.dataType){case "esriFieldTypeInteger":void 0===b||isNaN(b)||(a.presetValue=b);this._createNumberTypeDOM(a,d);break;case "esriFieldTypeDate":void 0!==b&&(a.presetValue={dateType:"fixed",dateTime:isNaN(b)?null:Number(b)});this._createDateTypeDOM(a,d);break;case "esriFieldTypeString":void 0!==b&&(a.presetValue=b);this._createStringTypeDOM(a,d);break;case "esriFieldTypeGUID":void 0!==b&&(a.presetValue=b),this._createGUIDTypeDOM(a,d)}this.parentNode.appendChild(c);
return c},_createTooltipContent:function(a){var b,c=!1,d=f.create("div");var e=f.create("div",{"class":"presetMessageContentDiv",style:{"max-height":"200px",overflow:"auto"},tabindex:"0"},d);var k=r.substitute(this.nls.presetGroupFieldsLabel,{groupName:"\x3cb\x3e"+a.name+"\x3c/b\x3e"});var l=r.substitute(this.nls.presetGroupNoFieldsLabel,{groupName:"\x3cb\x3e"+a.name+"\x3c/b\x3e"});k=f.create("div",{innerHTML:k},e);e=f.create("ul",{style:"margin: 0px; padding: 0 20px;"},e);for(b in a.appliedOn)if(0<
a.appliedOn[b].length){c=!0;var n=this._jimuLayerInfos.getLayerOrTableInfoById(b);if(n&&n.title&&n.layerObject&&n.layerObject.fields){f.create("li",{innerHTML:n.title+": "},e);var K=f.create("ul",{style:"margin: 0px;"},e);u.forEach(n.layerObject.fields,g.hitch(this,function(p){p=J.getDefaultPortalFieldInfo(p);0<=a.appliedOn[b].indexOf(p.fieldName)&&f.create("li",{innerHTML:p.label||p.fieldName},K)}))}}c||m.set(k,"innerHTML",l);this.tooltipContents[a.name]=d},_enableUsePresetValueCB:function(a){null!==
a&&""!==a&&void 0!==a&&(this.enableUsePresetValueCheckBox=!0)},_createNumberTypeDOM:function(a,b){b=new G({"class":"ee-inputField",name:a.name,value:a.presetValue,"aria-label":a.name},f.create("div",{},b));this.own(h(b,"change",g.hitch(this,function(c){a.presetValue=c;this.emit("presetValueChanged")})));this._enableUsePresetValueCB(a.presetValue)},_createDateTypeDOM:function(a,b){var c=new w({"class":"ee-inputField",name:a.name,disabled:!0,"aria-label":a.name,style:"width: calc(100% - 30px)",value:this.nls.relativeDates[a.presetValue.dateType]},
f.create("div",{},b));"fixed"===a.presetValue.dateType&&(a.presetValue.dateTime?c.set("value",t.getDateFromRelativeInfo(a.presetValue,!0)):c.set("value",""));m.set(c.focusNode,"disabled",!1);m.set(c.focusNode,"readonly",!0);m.set(c.focusNode,"tabindex",0);c.esriCTisDateGroup=!0;c.esriCTPresetGroup=a;var d=r.substitute(this.nls.editGroupInfoIcon,{groupName:a.name});b=f.create("div",{"class":"jimu-icon jimu-icon-edit",tabindex:"0",role:"button","aria-label":d},f.create("div",{"class":"editRelativeDateIcon"},
b));this.own(h(b,"click",g.hitch(this,function(){var e=new v({nls:this.nls,relativeDates:a.presetValue,map:this.map,layerInfos:this._jimuLayerInfos,selectedPresetValue:a.presetValue&&a.presetValue.chooseFromLayerInfo?a.presetValue.chooseFromLayerInfo.selectedValue:""});this.own(h(e,"updatePresetValue",g.hitch(this,function(k){a.presetValue=k;"fixed"===a.presetValue.dateType?a.presetValue.dateTime?c.set("value",t.getDateFromRelativeInfo(a.presetValue,!0)):c.set("value",""):c.set("value",this.nls.relativeDates[k.dateType]);
this.emit("presetValueChanged")})))})));this.own(h(b,"keydown",g.hitch(this,function(e){if(e.keyCode===q.ENTER||e.keyCode===q.SPACE)e=new v({nls:this.nls,relativeDates:a.presetValue,map:this.map,layerInfos:this._jimuLayerInfos,selectedPresetValue:a.presetValue&&a.presetValue.chooseFromLayerInfo?a.presetValue.chooseFromLayerInfo.selectedValue:""}),this.own(h(e,"updatePresetValue",g.hitch(this,function(k){a.presetValue=k;"fixed"===a.presetValue.dateType?a.presetValue.dateTime?c.set("value",t.getDateFromRelativeInfo(a.presetValue,
!0)):c.set("value",""):c.set("value",this.nls.relativeDates[k.dateType]);this.emit("presetValueChanged")})))})));this.own(h(c.domNode,B.enter,g.hitch(this,function(){var e=t.getDateFromRelativeInfo(a.presetValue,!0);""===e&&(e=this.nls.relativeDates.noDateDefinedTooltip);c.set("title",e)})));this._enableUsePresetValueCB(a.presetValue)},_createStringTypeDOM:function(a,b){b=new H({row:1,style:{resize:"vertical"},"class":"ee-inputField",name:a.name,"aria-label":a.name,value:a.presetValue},f.create("div",
{},b));this.own(h(b,"change",g.hitch(this,function(c){a.presetValue!==c&&(a.presetValue=c,this.emit("presetValueChanged"))})));this._enableUsePresetValueCB(a.presetValue)},_createGUIDTypeDOM:function(a,b){b=new w({"class":"ee-inputField","aria-label":a.name,name:a.name,value:a.presetValue},f.create("div",{},b));this.own(h(b,"change",g.hitch(this,function(c){a.presetValue=c;this.emit("presetValueChanged")})));this._enableUsePresetValueCB(a.presetValue)},_createDomainContentNode:function(a,b){var c=
this._populateDomains(a);var d=new E({"class":"ee-inputField",name:a.name,"aria-label":a.name,style:{width:"99%"},required:!1,store:new F({data:c.options})},f.create("div",{},b));d.esriCTDomainList=!0;this.own(h(d,"change",g.hitch(this,function(){a.selectedDomainValue=d.get("value");this.emit("presetValueChanged")})));d.set("value",c.defaultValue);this._enableUsePresetValueCB(a.presetValue);return d},_populateDomains:function(a){var b=[],c;u.forEach(a.presetValue,g.hitch(this,function(d){d.showInList&&
(b.push({name:d.label,id:d.value}),d.isDefault&&(c=d.value,a.selectedDomainValue=d.value))}));return{options:b,defaultValue:c}}})});