// 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/_base/array dojo/Deferred jimu/utils esri/tasks/query esri/tasks/QueryTask esri/layers/FeatureLayer".split(" "),function(t,g,h,n,u,p,q,w){function v(){return{queryTr:null,config:null,layerInfo:null,relationshipLayerInfos:null,relationshipPopupTemplates:null,queryType:-1,query:{maxRecordCount:1E3,resultLayer:null,where:"",geometry:null,relationship:null,nextIndex:0,foundedNum:0,allCount:0,objectIds:[]}}}t=t(null,{tempResultLayer:null,map:null,currentAttrs:null,
constructor:function(a,b){this.map=a;this.currentAttrs=b;0<this.currentAttrs.layerInfo.maxRecordCount&&(this.currentAttrs.query.maxRecordCount=this.currentAttrs.layerInfo.maxRecordCount)},resetCurrentAttrs:function(){this.currentAttrs=v()},getCurrentAttrs:function(){return this.currentAttrs},executeQueryForFirstTime:function(){var a=null;a=this.currentAttrs.query.where;var b=this.currentAttrs.query.geometry;return a=1===this.currentAttrs.queryType?this.doQuery_SupportOrderByAndPagination(a,b):2===
this.currentAttrs.queryType?this.doQuery_SupportObjectIds(a,b):this.doQuery_NotSupportObjectIds(a,b)},executeQueryWhenScrollToBottom:function(){var a=null;1===this.currentAttrs.queryType?a=this.onResultsScroll_SupportOrderByAndPagination():2===this.currentAttrs.queryType&&(a=this.onResultsScroll_SupportObjectIds());return a},_isServiceSupportsOrderBy:function(a){var b=!1;a.advancedQueryCapabilities&&a.advancedQueryCapabilities.supportsOrderBy&&(b=!0);return b},_isServiceSupportsPagination:function(a){var b=
!1;a.advancedQueryCapabilities&&a.advancedQueryCapabilities.supportsPagination&&(b=!0);return b},_tryLocaleNumber:function(a){var b=u.localizeNumber(a);if(null===b||void 0===b)b=a;return b},_tryLocaleDate:function(a){var b=u.localizeDate(a);b||(b=a.toLocaleDateString());return b},_getLayerIndexByLayerUrl:function(a){var b=a.lastIndexOf("/");a=a.slice(b+1,a.length);return parseInt(a,10)},_getServiceUrlByLayerUrl:function(a){var b=a.lastIndexOf("/");return a.slice(0,b)},_isSupportObjectIds:function(a){var b=
0;a.currentVersion&&(b=parseFloat(a.currentVersion));return 10<=b||a.hasOwnProperty("typeIdField")},_isImageServiceLayer:function(a){return-1<a.indexOf("/ImageServer")},_isTable:function(a){return"Table"===a.type},_getBestQueryName:function(a){for(var b=a=a?a+(" _"+this.nls.queryResult):a+this.nls.queryResult,e=h.map(this.map.graphicsLayerIds,g.hitch(this,function(c){return this.map.getLayer(c).name})),d=2;0<=h.indexOf(e,b);)b=a+"_"+d,d++;return b},getObjectIdsForAllRelatedRecordsAction:function(){var a=
new n;if(this.currentAttrs.query.objectIds&&0<this.currentAttrs.query.objectIds.length)a.resolve(this.currentAttrs.query.objectIds);else if(1===this.currentAttrs.queryType)a=this._queryIds(this.currentAttrs.query.where,this.currentAttrs.query.geometry,this.currentAttrs.query.relationship);else if(3===this.currentAttrs.queryType){var b=this.currentAttrs.config.objectIdField,e=h.map(this.currentAttrs.query.resultLayer.graphics,g.hitch(this,function(d){return parseInt(d.attributes[b],10)}));a.resolve(e)}return a},
doQuery_SupportOrderByAndPagination:function(a,b){var e=new n,d=g.hitch(this,function(f){console.error(f);e.reject(f)}),c=this.currentAttrs.query.relationship;this._queryCount(a,b,c).then(g.hitch(this,function(f){this.currentAttrs.query.allCount=f;if(0===f)e.resolve([]);else{this.currentAttrs.query.nextIndex=0;this.currentAttrs.query.foundedNum=0;var k=this.currentAttrs.query.maxRecordCount;this._queryWithPaginationAndOrder(a,b,0,k,c).then(g.hitch(this,function(m){m=m.features;this.currentAttrs.query.nextIndex+=
k;this.currentAttrs.query.foundedNum+=m.length;e.resolve(m)}),d)}}),d);return e},onResultsScroll_SupportOrderByAndPagination:function(){var a=new n,b=this.currentAttrs.query.nextIndex;if(this.currentAttrs.query.foundedNum>=this.currentAttrs.query.allCount)return a.resolve([]),a;var e=g.hitch(this,function(c){console.error(c);a.reject(c)}),d=this.currentAttrs.query.maxRecordCount;this._queryWithPaginationAndOrder(this.currentAttrs.query.where,this.currentAttrs.query.geometry,b,d,this.currentAttrs.query.relationship).then(g.hitch(this,
function(c){c=c.features;this.currentAttrs.query.nextIndex+=d;this.currentAttrs.query.foundedNum+=c.length;a.resolve(c)}),e);return a},doQuery_SupportObjectIds:function(a,b){var e=new n,d=g.hitch(this,function(f){console.error(f);e.reject(f)}),c=this.currentAttrs.query.relationship;this._queryIds(a,b,c).then(g.hitch(this,function(f){if(f&&0<f.length){var k=this.currentAttrs.query.allCount=f.length;this.currentAttrs.query.objectIds=f;this.currentAttrs.query.nextIndex=0;this.currentAttrs.query.foundedNum=
0;var m=this.currentAttrs.query.maxRecordCount,r=[];r=k>m?f.slice(0,m):f;this._queryByObjectIds(r,!0,c).then(g.hitch(this,function(l){l=l.features;this.currentAttrs.query.nextIndex+=r.length;this.currentAttrs.query.foundedNum+=l.length;e.resolve(l)}),g.hitch(this,function(l){d(l)}))}else this.currentAttrs.query.allCount=0,e.resolve([])}),d);return e},onResultsScroll_SupportObjectIds:function(){var a=new n,b=this.currentAttrs.query.objectIds,e=this.currentAttrs.query.nextIndex;if(this.currentAttrs.query.foundedNum>=
this.currentAttrs.query.allCount)a.resolve([]);else{var d=b.slice(e,e+Math.min(b.length-e,this.currentAttrs.query.maxRecordCount));if(0===d.length)a.resolve([]);else return this._queryByObjectIds(d,!0,this.currentAttrs.query.relationship).then(g.hitch(this,function(c){c=c.features;this.currentAttrs.query.nextIndex+=d.length;this.currentAttrs.query.foundedNum+=c.length;a.resolve(c)}),g.hitch(this,function(c){a.reject(c)})),a}},doQuery_NotSupportObjectIds:function(a,b){var e=new n;this._query(a,b,!0,
this.currentAttrs.query.relationship).then(g.hitch(this,function(d){d=d.features;this.currentAttrs.query.allCount=d.length;e.resolve(d)}),g.hitch(this,function(d){console.error(d);e.reject(d)}));return e},getOutputFields:function(){var a=[];h.forEach(this.currentAttrs.layerInfo.fields,g.hitch(this,function(b){b&&b.name&&"esriFieldTypeGeometry"!==b.type&&a.push(b.name)}));return a},_getObjectIdField:function(){return this.currentAttrs.config.objectIdField},_getRequiredFieldNames:function(){var a=g.clone(this.currentAttrs.layerInfo);
return(new w({layerDefinition:a,featureSet:null})).getOutFields()},_getPopupInfoFieldNames:function(){var a=[],b=[],e=h.filter(this.currentAttrs.layerInfo.fields,g.hitch(this,function(c){return"esriFieldTypeGeometry"!==c.type})),d=this.currentAttrs.config.popupInfo;b=b.concat(this._getPlaceholderFieldNames(e,d.title));d.description?b=b.concat(this._getPlaceholderFieldNames(e,d.description)):d.fieldInfos&&0<d.fieldInfos.length&&h.forEach(d.fieldInfos,g.hitch(this,function(c){c.visible&&b.push(c.fieldName)}));
d.mediaInfos&&0<d.mediaInfos.length&&h.forEach(d.mediaInfos,g.hitch(this,function(c){b=b.concat(this._getPlaceholderFieldNames(e,c.title));b=b.concat(this._getPlaceholderFieldNames(e,c.caption));if(c=c.value){var f=c.fields;f&&0<f.length&&h.forEach(f,g.hitch(this,function(k){b.push(k)}));c.normalizeField&&b.push(c.normalizeField);c.tooltipField&&b.push(c.tooltipField);c.sourceURL&&(b=b.concat(this._getPlaceholderFieldNames(e,c.sourceURL)));c.linkURL&&(b=b.concat(this._getPlaceholderFieldNames(e,c.linkURL)))}}));
h.forEach(b,g.hitch(this,function(c){0>a.indexOf(c)&&a.push(c)}));return a},_getPlaceholderFieldNames:function(a,b){var e=[];if(b){var d=[];h.forEach(a,g.hitch(this,function(c){c=c.name;0<=b.indexOf("{"+c+"}")&&d.push(c)}));h.forEach(d,g.hitch(this,function(c){0>e.indexOf(c)&&e.push(c)}))}return e},_query:function(a,b,e,d){var c=new p;c.where=a;b&&(c.geometry=b);c.outSpatialReference=this.map.spatialReference;c.returnGeometry=!!e;c.spatialRelationship=d;c.outFields=this.getOutputFields();return(new q(this.currentAttrs.config.url)).execute(c)},
_queryIds:function(a,b,e){var d=new p;d.where=a;b&&(d.geometry=b);d.returnGeometry=!1;d.spatialRelationship=e;d.outSpatialReference=this.map.spatialReference;return(new q(this.currentAttrs.config.url)).executeForIds(d)},_queryByObjectIds:function(a,b,e){var d=new n,c=new p;c.returnGeometry=!!b;c.outSpatialReference=this.map.spatialReference;c.outFields=this.getOutputFields();c.objectIds=a;c.spatialRelationship=e;(new q(this.currentAttrs.config.url)).execute(c).then(g.hitch(this,function(f){d.resolve(f)}),
g.hitch(this,function(f){if(400===f.code){var k=this._getObjectIdField(),m="",r=a.length;h.forEach(a,g.hitch(this,function(l,x){m+=k+" \x3d "+l;x!==r-1&&(m+=" OR ")}));this._query(m,null,b,e).then(g.hitch(this,function(l){d.resolve(l)}),g.hitch(this,function(l){d.reject(l)}))}else d.reject(f)}));return d},_queryCount:function(a,b,e){var d=new p;d.where=a;b&&(d.geometry=b);d.returnGeometry=!1;d.outSpatialReference=this.map.spatialReference;d.spatialRelationship=e;return(new q(this.currentAttrs.config.url)).executeForCount(d)},
_queryWithPaginationAndOrder:function(a,b,e,d,c){var f=new p;f.where=a;b&&(f.geometry=b);f.outSpatialReference=this.map.spatialReference;f.returnGeometry=!0;f.spatialRelationship=c;f.outFields=this.getOutputFields();f.start=e;f.num=d;(a=this.currentAttrs.config.orderByFields)&&0<a.length&&(f.orderByFields=a,a=h.map(a,g.hitch(this,function(k){return k.split(" ")[0]})),h.forEach(a,g.hitch(this,function(k){0>f.outFields.indexOf(k)&&f.outFields.push(k)})));return(new q(this.currentAttrs.config.url)).execute(f)}});
t.getCleanCurrentAttrsTemplate=v;return t});