// 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/array","dojo/Deferred","jimu/LayerInfos/LayerInfos"],function(l,d,m,n){return l(null,{config:null,constructor:function(a,b){this.config=a;this.map=b;"layerOrder"in this.config&&0!==this.config.layerOrder.length||(this.config.layerOrder=this.getCandidateParamNames(!1))},getCandidateParamNames:function(a){var b=[];if(!this.config)return b;d.forEach(this.config.outputParams,function(c){"GPFeatureRecordSetLayer"!==c.dataType||a&&!0===this.config.useResultMapServer||
b.push(c.name)},this);d.forEach(this.config.inputParams,function(c){"GPFeatureRecordSetLayer"!==c.dataType||a&&"draw"!==c.featureSetMode||b.push(c.name)},this);return b},getOrderableInput:function(){var a=[];if(!this.config)return a;d.forEach(this.config.inputParams,function(b){"GPFeatureRecordSetLayer"===b.dataType&&"draw"===b.featureSetMode&&a.push(b.name)},this);return d.filter(this.config.layerOrder,function(b){return-1!==d.indexOf(a,b)},this)},getOrderableOutput:function(){var a=[];if(!this.config)return a;
d.forEach(this.config.outputParams,function(b){"GPFeatureRecordSetLayer"===b.dataType&&!0!==this.config.useResultMapServer&&a.push(b.name)},this);return d.filter(this.config.layerOrder,function(b){return-1!==d.indexOf(a,b)},this)},calculateLayerIndex:function(a,b){if(!this.map)throw Error("The map cannot be null in LayerOrderUtil.calculateLayerIndex");var c=new m,h=this.config.layerOrder;var g=d.indexOf(h,a);if(-1===g)throw Error(a+"cannot be found in the orderable params");for(a=g-1;0<=a;a--){var f=
d.indexOf(this.map.graphicsLayerIds,b+h[a]);if(-1!==f)return c.resolve(f),c}a=g+1;for(g=h.length;a<g;a++)if(f=d.indexOf(this.map.graphicsLayerIds,b+h[a]),-1!==f)return c.resolve(f+1),c;c.isResolved()||n.getInstance(this.map,this.map.itemInfo).then(function(e){e=e.getMapNotesLayerInfoArray();if(0===e.length)c.resolve(-1);else{e=e[e.length-1];var k=e.getSubLayers();e=0===k.length?e.layerObject.id:k[k.length-1].layerObject.id;f=d.indexOf(this.map.graphicsLayerIds,e);c.resolve(f)}});return c}})});