// 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/array dojo/_base/declare dojo/_base/lang dojo/dom-class dojo/dom-construct dojo/_base/html dojo/on dojo/string jimu/dijit/_GeocodeServiceChooserContent jimu/dijit/Popup jimu/dijit/LoadingShelter jimu/portalUrlUtils jimu/dijit/Message esri/request esri/lang ./convert ./QuerySourceSetting ./settingComponents ./SettingBoxedDivs ./SettingBufferBlock ./SettingCheckboxLabeled ./SettingContainer ./SettingDropdownLabeled ./SettingFieldListLabeled ./SettingInputLabeled ./SettingObject ./SettingOptionsTable ./SettingStaticText".split(" "),
function(h,A,e,t,u,q,k,r,B,C,D,v,w,E,F,x,G,m,H,y,n,p,I,J,g,K,L,z){return A(K,{_inputControl:null,_mainControl:null,_detailsDiv:null,_detailsTitle:null,_detailsCheckbox:null,_sourceDisplay:null,_iCurrentSource:-1,_sourceMenuItems:[],_newSourceTypeMenuItems:[],_nls:null,_webmapFeatureLayers:[],_fieldListPicker:null,_displayFieldInput:null,constructor:function(c,b,a,d,f,l){this._nls=b;this._map=d;this._webmapFeatureLayers=f;this._portalUrl=l;this._newSourceTypeMenuItems=[b.groupingLabels.featureLayerDetails,
b.groupingLabels.geocoderDetails];this._inputControl=new L(null,"third-width","",b.propertyLabels.name,null,"",e.hitch(this,this._onRowSelected),e.hitch(this,this._onRowDeleted),e.hitch(this,this._onRowMoved));this._detailsDiv=m.container("two-thirds-width","majorTrailingVertGap",[]);c=m.addTextButtonDropdownCtl("",b.buttons.addSearchSource,this._newSourceTypeMenuItems);this.own(k(c.ctl,"click",e.hitch(this,this._onAddSearchSourceMenuItemClick)));this._mainControl=new p(null,a||"","majorTrailingVertGap",
b.groupingLabels.searchSources,"full-width",[new g("allPlaceholder",!1,"full-width","third-width","two-thirds-width",b.propertyLabels.placeholderTextForAllSources),new n("showInfoWindowOnSelect","full-width","third-width","two-thirds-width",b.propertyLabels.showPopupForFoundItem),new H(null,[c.div,m.container("full-width flexbox","majorTrailingHorizGap",[this._inputControl.div(),this._detailsDiv])])]);this._mainDiv=this._mainControl.div()},setConfig:function(){this._mainControl.setConfig(this._config);
this._sourceMenuItems=h.map(this._config.sources,function(c){return{item:c.name}});this._inputControl.setValue(this._sourceMenuItems);0<this._sourceMenuItems.length&&this._inputControl.selectTableRow(0)},getConfig:function(c,b){this._mainControl.getConfig(this._config);this._setDetails(-1);h.forEach(this._config.sources,function(a){"locator"===a.type?a.url||b.push(r.substitute(this._nls.problems.noSearchSourceURL,{sourceName:a.name})):0===a.searchFields.length&&b.push(r.substitute(this._nls.problems.noSearchSourceFields,
{sourceName:a.name}));0>a.buffer.bufferUnitsMenu[0].indexOf("1")&&b.push(r.substitute(this._nls.problems.noBufferUnitsForSearchSource,{sourceName:a.name}))},this)},_onAddSearchSourceMenuItemClick:function(c){var b={};if(c.target.innerText===this._newSourceTypeMenuItems[0]){var a=new G({nls:this._nls.querySourceSetting,map:this._map,appConfig:{portalUrl:this._portalUrl}});var d=e.clone(this._config.searchSourceTemplates.query);a.setConfig({name:d.name||"",placeholder:d.placeholder||"",searchFields:d.searchFields||
[],displayField:d.displayField||"",maxSuggestions:d.maxSuggestions||6,maxResults:d.maxResults||6,zoomScale:d.zoomScale||5E4,exactMatch:d.exactMatch,searchInCurrentMapExtent:d.searchInCurrentMapExtent,type:d.type||"query",layerId:d.layerId,url:d.url||""});a._openQuerySourceChooser();a.own(k(a,"select-query-source-ok",e.hitch(this,function(f){d.name=f.name;d.layerId=f.layerInfo?f.layerInfo.id:null;d.url=f.url;d.buffer=e.clone(this._config.bufferTemplate);d.fieldMenuItems=[];(f=f.definition&&f.definition.fields)&&
h.map(f,function(l){d.fieldMenuItems.push({label:l.alias||l.name,value:l.name})});this._config.sources.push(d);b.item=d.name;this._sourceMenuItems.push(b);this._inputControl.addRowToTable(b);this._inputControl.selectTableRow(this._config.sources.length-1);a.destroy();a=null})));a.own(k(a,"select-query-source-cancel",function(){a.destroy();a=null}))}else d=e.clone(this._config.searchSourceTemplates.locator),d.buffer=e.clone(this._config.bufferTemplate),this._openServiceChooser(d,b)},_openServiceChooser:function(c,
b){var a=c&&b?!1:!0;this.serviceChooserContent=new B({url:a?this._sourceDisplay._contents[0].getValue():""});this.shelter=new D({hidden:!0});this.geocoderPopup=new C({titleLabel:this._nls.querySourceSetting.setGeocoderURL,autoHeight:!0,content:this.serviceChooserContent.domNode,container:window.jimuConfig.layoutId,width:640,configItem:c||this._config.sources[this._iCurrentSource],menuEntry:b||this._sourceMenuItems[this._iCurrentSource],update:a});this.shelter.placeAt(this.geocoderPopup.domNode);q.setStyle(this.serviceChooserContent.domNode,
"width","580px");q.addClass(this.serviceChooserContent.domNode,"override-geocode-service-chooser-content");this.serviceChooserContent.own(k(this.serviceChooserContent,"validate-click",e.hitch(this,function(){q.removeClass(this.serviceChooserContent.domNode,"override-geocode-service-chooser-content")})));this.serviceChooserContent.own(k(this.serviceChooserContent,"ok",e.hitch(this,"_onSelectLocatorUrlOk")));this.serviceChooserContent.own(k(this.serviceChooserContent,"cancel",e.hitch(this,"_onSelectLocatorUrlCancel")))},
_onSelectLocatorUrlOk:function(c){if(c&&c[0]&&c[0].url){this.shelter.show();var b=c[0].url;E({url:b,content:{f:"json"},handleAs:"json",callbackParamName:"callback"}).then(e.hitch(this,function(a){this.shelter.hide();if(a&&a.singleLineAddressField&&a.singleLineAddressField.name){var d=this.geocoderPopup.configItem;d.singleLineFieldName=a.singleLineAddressField.name;"string"===typeof b?(a=b.split("/"),d.name=a[a.length-2]||"geocoder"):d.name="geocoder";d.url=b;a=this.geocoderPopup.menuEntry;a.item=
d.name;this._sourceDisplay&&this._sourceDisplay._contents&&this._sourceDisplay._contents[0]&&this._sourceDisplay._contents[0].getValue&&this._sourceDisplay._contents[0].getValue()!==b&&(this._sourceDisplay._contents[0].setValue(b),this._sourceDisplay._contents[1].setValue(d.name));this.geocoderPopup.update?(this._config.sources[this._iCurrentSource]=d,this._sourceMenuItems[this._iCurrentSource]=a):(this._config.sources.push(d),this._sourceMenuItems.push(a),this._inputControl.addRowToTable(a));this._setDetails(this._iCurrentSource);
this._inputControl.selectTableRow(this.geocoderPopup.update?this._iCurrentSource:this._config.sources.length-1);this.geocoderPopup&&(this.geocoderPopup.close(),this.geocoderPopup=null)}else new w({message:this._nls.querySourceSetting.locatorWarning})}),e.hitch(this,function(a){console.error(a);this.shelter.hide();new w({message:F.substitute({URL:this._getRequestUrl(b)},e.clone(this._nls.querySourceSetting.invalidUrlTip))})}))}},_getRequestUrl:function(c){var b=window.location.protocol;return"http:"===
b?v.setHttpProtocol(c):"https:"===b?v.setHttpsProtocol(c):c},_onSelectLocatorUrlCancel:function(){this.geocoderPopup&&(this.geocoderPopup.close(),this.geocoderPopup=null,this.emit("select-locator-url-cancel"))},_setDetails:function(c){var b=this._sourceMenuItems.length;this._removeCurrentDetails();if(0<=c&&c<b){b=this._config.sources[c];if("query"===b.type)this._fieldListPicker=new J("searchFields",this._nls,"full-width","details-label","details-value",this._nls.propertyLabels.searchFields,this._nls.hints.csvNameList,
b.fieldMenuItems),this._displayFieldInput=new I("displayField","full-width","details-label","details-value",this._nls.propertyLabels.displayField,"",b.fieldMenuItems,e.hitch(this,this._onChangeField)),this._sourceDisplay=new p(null,"","majorTrailingVertGap",this._nls.groupingLabels.featureLayerDetails,"full-width",[new p(null,"full-width","minorTrailingHorizGap",[new z(null,"details-label inline-block",this._nls.querySourceSetting.layerSource),new z(null,"details-value inline-block wrapText",b.url)]),
new g("name",!1,"full-width","details-label","details-value",this._nls.propertyLabels.name,b.name),new g("placeholder",!1,"full-width","details-label","details-value",this._nls.propertyLabels.placeholderText),this._fieldListPicker,this._displayFieldInput,new g("maxSuggestions",!0,"full-width","details-label","details-value",this._nls.propertyLabels.maximumSuggestions,"6",null,null,null,{min:1,max:10,places:0}),new g("maxResults",!0,"full-width","details-label","details-value",this._nls.propertyLabels.maximumResults,
"6",null,null,null,{min:1,max:10,places:0}),new g("zoomScale",!0,"full-width","details-label","details-value",this._nls.propertyLabels.zoomScale,"50000","","1:",null,{min:0,places:0}),new n("exactMatch","full-width","details-label","details-value",this._nls.propertyLabels.exactMatch),new n("searchInCurrentMapExtent","full-width","details-label","details-value",this._nls.propertyLabels.limitSearchToMapExtent),new y("buffer",this._nls,"full-width","details-label","details-value",this._config.bufferTemplate,
this._nls.propertyLabels.bufferDefaultDistance,"100")]);else if("locator"===b.type){var a=m.textButtonCtl("",this._nls.querySourceSetting.set,this._nls.querySourceSetting.set);this.own(k(a.ctl,"click",e.hitch(this,this._openServiceChooser,void 0,void 0)));this._sourceDisplay=new p(null,"","majorTrailingVertGap",this._nls.groupingLabels.geocoderDetails,"full-width",[new g("url",!1,"full-width","details-label","details-value",this._nls.propertyLabels.url,void 0,void 0,void 0,a,void 0,!0),new g("name",
!1,"full-width","details-label","details-value",this._nls.propertyLabels.name),new g("placeholder",!1,"full-width","details-label","details-value",this._nls.propertyLabels.placeholderText),new g("countryCode",!1,"full-width","details-label","details-value",this._nls.propertyLabels.countryRegionCodes,this._nls.placeholders.countryRegionCodes),new g("maxSuggestions",!0,"full-width","details-label","details-value",this._nls.propertyLabels.maximumSuggestions,"6",null,null,null,{min:1,max:10,places:0}),
new g("maxResults",!0,"full-width","details-label","details-value",this._nls.propertyLabels.maximumResults,"6",null,null,null,{min:1,max:10,places:0}),new g("zoomScale",!0,"full-width","details-label","details-value",this._nls.propertyLabels.zoomScale,"50000","","1:",null,{min:0,places:0}),new n("searchInCurrentMapExtent","full-width","details-label","details-value",this._nls.propertyLabels.limitSearchToMapExtent),new y("buffer",this._nls,"full-width","details-label","details-value",this._config.bufferTemplate,
this._nls.propertyLabels.bufferDefaultDistance,"100")])}this._sourceDisplay&&(b.buffer.bufferUnitsMenu=x.unitCodesToLabels(jimuNls.units,b.buffer.bufferUnitsMenu),this._sourceDisplay.setConfig(b),u.place(this._sourceDisplay.div(),this._detailsDiv),t.remove(this._detailsDiv,"hidden"),this._iCurrentSource=c)}},_convertLayerIdToLayerName:function(c){var b=c;h.some(this._webmapFeatureLayers,function(a){return a.layerId===c?(b=a.name,!0):!1});return b},_convertLayerNameToLayerId:function(c){var b=c;h.some(this._webmapFeatureLayers,
function(a){return a.name===c?(b=a.layerId,!0):!1});return b},_onChangeFeatureLayer:function(c){var b=[];if(0<=this._iCurrentSource){var a=this._config.sources[this._iCurrentSource];h.some(this._webmapFeatureLayers,e.hitch(this,function(d){return c===d.layerId?(a.name=d.layerId,a.searchFields=[],a.displayField=d.displayField,a.layerId=d.layerId,a.url=d.url,h.map(d.fields,function(f){b.push({label:f.alias||f.name,value:f.name})}),this._fieldListPicker.setFieldList(b),this._fieldListPicker.setDisplay(),
this._displayFieldInput.setOptions(b),this._inputControl.renameTableRow(this._iCurrentSource,d.name),!0):!1}))}},_onChangeField:function(c){if(0<=this._iCurrentSource){var b=this._config.sources[this._iCurrentSource];b.displayField=c}},_onRowSelected:function(c){this._setDetails(c.rowIndex)},_onRowMoved:function(c,b){this._removeCurrentDetails();var a=b?c.rowIndex+1:c.rowIndex-1;b=this._sourceMenuItems.splice(a,1);a=this._config.sources.splice(a,1);this._sourceMenuItems.splice(c.rowIndex,0,b[0]);
this._config.sources.splice(c.rowIndex,0,a[0]);this._inputControl.selectTableRow(c.rowIndex)},_onRowDeleted:function(c,b,a){this._removeCurrentDetails();this._sourceMenuItems.splice(a,1);this._config.sources.splice(a,1);0<this._sourceMenuItems.length&&this._inputControl.selectTableRow(0)},_removeCurrentDetails:function(){if(0<=this._iCurrentSource){t.add(this._detailsDiv,"hidden");var c=this._config.sources[this._iCurrentSource];this._sourceDisplay.getConfig(c);c.buffer.bufferUnitsMenu=x.labelsToUnitCodes(jimuNls.units,
c.buffer.bufferUnitsMenu);"query"===c.type&&(c.name=this._convertLayerIdToLayerName(c.name));u.empty(this._detailsDiv);this._sourceDisplay=null;this._iCurrentSource=-1}}})});