// 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/aspect","dojo/io-query","esri/InfoTemplate","esri/layers/WFSLayer"],function(r,y,v,z,w){return{checkMixedContent:function(a){"string"===typeof window.location.href&&0===window.location.href.indexOf("https://")&&"string"===typeof a&&0===a.indexOf("http://")&&(a="https:"+a.substring("5"));return a},endsWith:function(a,b){return-1!==a.indexOf(b,a.length-b.length)},escapeForLucene:function(a){return a.replace(/(\+|\-|\&|\!|\(|\)|\{|\}|\[|\]|\^|\"|\~|\*|\?|\:|\\)/g,"\\$1")},
findLayersAdded:function(a,b){var d=[],e=[],g=[],h={itemIds:e,layers:g};if(!a)return h;var k="string"===typeof b&&0<b.length;r.forEach(a.layerIds,function(c){d.push(c)});r.forEach(a.graphicsLayerIds,function(c){d.push(c)});r.forEach(d,function(c){(c=a.getLayer(c))&&"string"===typeof c.xtnItemId&&0<c.xtnItemId.length&&(!k||c.xtnItemId===b)&&(g.push(c),-1===e.indexOf(c.xtnItemId)&&e.push(c.xtnItemId))});return h},loadWFSByUrl:function(a,b,d,e,g,h){var k,c,n,x=this.makeOGCRequestInfo(e);e=x.url;var t=
new w;var p=t.on("error",function(l){p&&p.remove();a.reject(l.error)});t.fromJson(x,function(l){try{if(p&&p.remove(),l&&l.push&&0<l.length){var u=l[0],m={url:e,version:t._version,name:u.name};n=u.name||u.title;if("string"===typeof m.version&&0<m.version.length&&"string"===typeof m.name&&0<m.name.length){var f=new w({id:g,infoTemplate:new z});"string"===typeof n&&0<n.length&&(f.name=n);k=f.on("error",function(q){k&&k.remove();a.reject(q.error)});c=y.after(f,"_describeFeatureTypeResponse",function(){c&&
c.remove();f.fields&&0<f.fields.length&&d._setFeatureLayerInfoTemplate(f)});f.fromJson(m,function(){k&&k.remove();f.xtnAddData=!0;b&&h&&b.addLayer(f);a.resolve(f)})}else a.reject(Error("Error loading WFSLayer, missing version and/or layer"))}else a.reject(Error("Error loading WFSLayer, no layers"))}catch(q){console.warn("Error loading WFSLayer",e),console.error(q),a.reject(q)}})},makeOGCRequestInfo:function(a){var b={url:a},d=a.indexOf("?");if(-1!==d){b.url=a.substring(0,d);var e;a=a.substring(d+
1,a.length);if("string"===typeof a&&0<a.length){var g=v.queryToObject(a),h={};if(g){for(e in g)g.hasOwnProperty(e)&&(a=g[e],d=e.toLowerCase(),"request"!==d&&"service"!==d&&("version"===d?"string"===typeof a&&0<a.length&&(b.version=a):"name"===d?"string"===typeof a&&0<a.length&&(b.name=a):h[e]=a));a=v.objectToQuery(h);"string"===typeof a&&0<a.length&&(b.url=b.url+"?"+a)}}}return b},setNodeText:function(a,b){a.innerHTML="";b&&a.appendChild(document.createTextNode(b))},setNodeTitle:function(a,b){a.title=
"";b&&a.setAttribute("title",b)},setNodeHTML:function(a,b){a.innerHTML="";b&&(a.innerHTML=b)}}});