// 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("require exports ../../baUtil/array dojo/store/util/SimpleQueryEngine ./ObjectUtil esri/dijit/geoenrichment/utils/ArrayUtil".split(" "),function(x,y,n,v,m,p){function t(a,b){a.some(function(e,c){b.func(e,c,b,a);if(b.stop)return!0});return b}function w(a){var b=a.split(" "),e=b[1];a={};switch(b[0]){case "max":a.result=-Infinity;b=function(c,d,f){f.result=Math.max(f.result,m.getObject(c,e))};break;case "min":a.result=Infinity;b=function(c,d,f){f.result=Math.min(f.result,m.getObject(c,e))};break;
case "sum":a.result=0;b=function(c,d,f){f.result+=m.getObject(c,e)};break;case "random":a.result=void 0;b=function(c,d,f,g){f.result=g[Math.round((g.length-1)*Math.random())];f.stop=!0};break;default:throw Error("Unsupported query.");}a.func=b;return a}var q={getSorting:function(a,b){if(!a)return m.compare;if("function"===typeof a)return a;var e=Array.isArray(a)?a:a.sort||[a];var c={};"string"===typeof b&&(b=[b]);Array.isArray(b)?b.forEach(function(d){c[d]=m.compareNames}):b&&(c=b);return function(d,
f){for(var g=void 0,h=0;g=e[h];h++){var k=d[g.attribute],l=f[g.attribute];if(k=(c[g.attribute]||(c["*"]?c["*"].bind(null,g.attribute):m.compare))(k,l,!1,!1,d,f))return g.descending?-k:k}return 0}},sort:function(a,b,e){return a.sort(q.getSorting(b,e))},sortIndices:function(a,b,e){a=n.map(a,function(d,f){return{value:d,index:f}});var c=q.getSorting(b,e);a.sort(function(d,f){return c(d.value,f.value)});return n.map(a,function(d){return d.index})},getQueryEngine:function(a,b){return function(e,c){c&&
c.sort&&(c=Object.assign({},c),c.sort=q.getSorting(c.sort,a));return(b||v)(e,c)}},objectToArray:function(a,b){void 0===b&&(b=null);var e=[],c=b?function(g){return a[g]?a[g][b]:void 0}:function(g){return a[g]},d;for(d in a){var f=c(d);"undefined"!==typeof f&&e.push(f)}return e},arrayToObject:function(a,b){var e={},c=p.composeIdentityFunction(b);n.forEach(a,function(d){e[c(d)]=d});return e},composeIdentityFunction:p.composeIdentityFunction,removeDuplicates:p.removeDuplicates,splitArrayToBunches:p.splitArrayToBunches,
contains:function(a,b){return-1!==n.indexOfLoose(a,b)},remove:function(a,b){b=n.indexOfLoose(a,b);-1!==b&&a.splice(b,1);return-1!==b},merge:function(a,b){a=a||[];null!=b&&Array.prototype.push.apply(a,b);return a},listToArray:function(a,b){if(null==a)return[];void 0===b&&(b=",");a="string"===typeof a?a.split(b):a.slice();for(b=0;b<a.length;b++)"string"===typeof a[b]&&(a[b]=a[b].trim());return a},reorderArray:function(a,b){var e=a.length,c=0,d=Array(e),f={},g={},h;for(h in b){var k=Math.round(h);if(0<=
k&&k<e&&!f[k]){var l=Math.round(b[h]);0<=l&&l<e&&!g[l]&&(d[l]=a[k],f[k]=1,g[l]=1,c++)}}c!==e&&(d=d.filter(function(u,r){return g[r]}),a.forEach(function(u,r){!f[r]&&d.push(u)}));return d},mapIndices:function(a,b,e,c){c=null==c?null:c;if(1===a)e.call(c,0,Math.floor(b/2));else{b=(b-1)/(a-1);for(var d=0;d<a;d++)e.call(c,d,Math.floor(.5+d*b))}},moveElement:function(a,b,e,c){var d=Array.isArray(b)?b:[b];if(-1!==d.indexOf(e))return a.slice();var f=[];a.forEach(function(g){-1===d.indexOf(g)&&(g==e?"before"===
c?(d.forEach(function(h){f.push(h)}),f.push(e)):"after"===c&&(f.push(e),d.forEach(function(h){f.push(h)})):f.push(g))});return f},min:function(a,b){var e=a.length;switch(e){case 0:return null;case 1:return a[0];default:for(var c=a[0],d=b(c),f=0,g=1;g<e;g++){var h=b(a[g]);d>h&&(c=a[g],d=h,f=g)}return{key:f,value:c,comparisonValue:d}}},max:function(a,b){var e=a.length;switch(e){case 0:return null;case 1:return a[0];default:for(var c=a[0],d=b(c),f=0,g=1;g<e;g++){var h=b(a[g]);d<h&&(c=a[g],d=h,f=g)}return{key:f,
value:c,comparisonValue:d}}},query:function(a,b){if("object"===typeof b)return t(a,b);if("string"===typeof b)return b=w(b),t(a,b).result},everyEqualProperty:function(a,b){if(2>a.length)return!0;var e;return!a.some(function(c,d){if(0===d)e=c[b];else if(e!==c[b])return!0})}};return q});