/*
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"],(function(e,r,t){"use strict";function o(e,r){const o=r&&r.url&&r.url.path;if(e&&o&&(e=t.makeAbsolute(e,o,{preserveProtocolRelative:!0}),r.portalItem&&r.readResourcePaths)){const o=t.makeRelative(e,r.portalItem.itemUrl);i.test(o)&&r.readResourcePaths.push(r.portalItem.resourceFromPath(o).path)}return m(e,r&&r.portal)}function l(r,o,l=e.MarkKeep.YES){if(!r)return r;!t.isAbsolute(r)&&o&&o.blockedRelativeUrls&&o.blockedRelativeUrls.push(r);let s=t.makeAbsolute(r);if(o){const e=o.verifyItemRelativeUrls&&o.verifyItemRelativeUrls.rootPath||o.url&&o.url.path;if(e){const l=m(e,o.portal);s=t.makeRelative(m(s,o.portal),l,l),s!==r&&o.verifyItemRelativeUrls&&o.verifyItemRelativeUrls.writtenUrls.push(s)}}return s=c(s,o&&o.portal),t.isAbsolute(s)&&(s=t.normalize(s)),null!=o&&o.resources&&null!=o&&o.portalItem&&!t.isAbsolute(s)&&!t.isDataProtocol(s)&&l===e.MarkKeep.YES&&o.resources.toKeep.push({resource:o.portalItem.resourceFromPath(s)}),s}function s(e,r,t){return o(e,t)}function a(e,r,t,o){const s=l(e,o);void 0!==s&&(r[t]=s)}const n=/\/items\/([^\/]+)\/resources\//,i=/^\.\/resources\//;function u(e){const t=r.isSome(e)?e.match(n):null;return r.isSome(t)?t[1]:null}function c(e,r){return r&&!r.isPortal&&r.urlKey&&r.customBaseUrl?t.changeDomain(e,`${r.urlKey}.${r.customBaseUrl}`,r.portalHostname):e}function m(e,r){if(!r||r.isPortal||!r.urlKey||!r.customBaseUrl)return e;const o=`${r.urlKey}.${r.customBaseUrl}`,l=t.getAppUrl();return t.hasSameOrigin(l,`${l.scheme}://${o}`)?t.changeDomain(e,r.portalHostname,o):t.changeDomain(e,o,r.portalHostname)}var p;e.MarkKeep=void 0,(p=e.MarkKeep||(e.MarkKeep={}))[p.YES=0]="YES",p[p.NO=1]="NO";const f=Object.freeze(Object.defineProperty({__proto__:null,fromJSON:o,toJSON:l,read:s,write:a,itemIdFromResourceUrl:u,ensureMainOnlineDomain:c,get MarkKeep(){return e.MarkKeep}},Symbol.toStringTag,{value:"Module"}));e.ensureMainOnlineDomain=c,e.fromJSON=o,e.itemIdFromResourceUrl=u,e.persistableUrlUtils=f,e.read=s,e.toJSON=l,e.write=a}));
