/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.24/esri/copyright.txt for details.
*/
define(["exports","../../core/maybe","../../core/urlUtils","../../chunks/persistableUrlUtils"],(function(e,r,t,s){"use strict";const n={mapserver:"MapServer",imageserver:"ImageServer",featureserver:"FeatureServer",sceneserver:"SceneServer",streamserver:"StreamServer",vectortileserver:"VectorTileServer"},i=Object.values(n),l=new RegExp(`^((?:https?:)?\\/\\/\\S+?\\/rest\\/services\\/(.+?)\\/(${i.join("|")}))(?:\\/(?:layers\\/)?(\\d+))?`,"i"),o=new RegExp(`^((?:https?:)?\\/\\/\\S+?\\/([^\\/\\n]+)\\/(${i.join("|")}))(?:\\/(?:layers\\/)?(\\d+))?`,"i"),u=/(.*?)\/(?:layers\/)?(\d+)\/?$/i;function a(e){return!!l.test(e)}function c(e){if(r.isNone(e))return null;const s=t.urlToObject(e),i=s.path.match(l)||s.path.match(o);if(!i)return null;const[,u,a,c,v]=i,m=a.indexOf("/");return{title:d(-1!==m?a.slice(m+1):a),serverType:n[c.toLowerCase()],sublayer:null!=v&&""!==v?parseInt(v,10):null,url:{path:u}}}function v(e){const r=t.urlToObject(e).path.match(u);return r?{serviceUrl:r[1],sublayerId:Number(r[2])}:null}function d(e){return(e=e.replace(/\s*[/_]+\s*/g," "))[0].toUpperCase()+e.slice(1)}function m(e,t){const s=[];if(e){const t=c(e);r.isSome(t)&&t.title&&s.push(t.title)}if(t){const e=d(t);s.push(e)}if(2===s.length){if(s[0].toLowerCase().includes(s[1].toLowerCase()))return s[0];if(s[1].toLowerCase().includes(s[0].toLowerCase()))return s[1]}return s.join(" - ")}function f(e){if(!e)return!1;const r=".arcgis.com/",t="//services",s="//tiles",n="//features",i=(e=e.toLowerCase()).includes(r),l=e.includes(t)||e.includes(s)||e.includes(n);return i&&l}function S(e,r){return r&&e&&e.toLowerCase().includes(r.toLowerCase())}function p(e,r){return e?t.removeTrailingSlash(t.removeQueryParameters(e,r)):e}function y(e){let{url:s}=e;if(!s)return{url:s};s=t.removeQueryParameters(s,e.logger);const n=t.urlToObject(s),i=c(n.path);let l;if(r.isSome(i))null!=i.sublayer&&null==e.layer.layerId&&(l=i.sublayer),s=i.url.path;else if(e.nonStandardUrlAllowed){const e=v(n.path);r.isSome(e)&&(s=e.serviceUrl,l=e.sublayerId)}return{url:t.removeTrailingSlash(s),layerId:l}}function h(e,r,n,i,l){s.write(r,i,"url",l),i.url&&null!=e.layerId&&(i.url=t.join(i.url,n,e.layerId.toString()))}function w(e){if(!e)return!1;const r=e.toLowerCase(),t=r.includes("/services/"),s=r.includes("/mapserver/wmsserver"),n=r.includes("/imageserver/wmsserver"),i=r.includes("/wmsserver");return t&&(s||n||i)}function g(e){if(!e)return!1;const r=new t.Url(t.makeAbsolute(e)).authority.toLowerCase();return"server.arcgisonline.com"===r||"services.arcgisonline.com"===r}function b(e){if(!e)return!1;return new t.Url(t.makeAbsolute(e)).authority.toLowerCase().includes("arcgis.com")}e.cleanTitle=d,e.isAGOLUrl=b,e.isArcGISUrl=a,e.isHostedAgolService=f,e.isHostedSecuredProxyService=S,e.isServerOrServicesAGOLUrl=g,e.isWmsServer=w,e.parse=c,e.parseNonStandardSublayerUrl=v,e.sanitizeUrl=p,e.sanitizeUrlWithLayerId=y,e.serverTypes=i,e.titleFromUrlAndName=m,e.writeUrlWithLayerId=h,Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
