/*
All material copyright Esri, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/5.0/esri/copyright.txt for details.
*/
import s from"../config.js";import{getOrigin as t}from"../core/urlUtils.js";const e=new Set(["elevation3d.arcgis.com","js.arcgis.com","jsdev.arcgis.com","jsqa.arcgis.com","static.arcgis.com"]);function r(t){if(!a(t))return null;const e=s=>s instanceof RegExp?s.test(t):"string"==typeof s&&t.startsWith(s),r=s.apiKeys;if(Array.isArray(r.scopes))for(const s of r.scopes)if(Array.isArray(s.urls)){if(s.urls.some(e))return s.token}else if(e(s.urls))return s.token;return r.basemapStyles&&/^https?:\/\/(i?basemaps|basemapstyles)-api\.arcgis\.com\//i.test(t)?r.basemapStyles:s.apiKey&&/^https?:\/\/.+\.arcgis\.com(\/|$)/i.test(t)?s.apiKey:null}function i(){return null!=s.apiKey||null!=s.apiKeys.basemapStyles}function n(s,t){return t?a(s):null!=r(s)}function a(s){const r=t(s,!0);return!!r&&(!e.has(r)&&!s.endsWith("/sharing/rest/generateToken"))}export{r as getApiKey,i as hasBasemapStylesApiKey,n as isApiKeyApplicable,a as supportsApiKey};
