/* COPYRIGHT Esri - https://js.arcgis.com/5.0/LICENSE.txt */
import e from"../Basemap.js";import r from"../core/Collection.js";import s from"../core/Logger.js";import{ensureType as o}from"../core/accessorSupport/ensureType.js";import{hasBasemapStylesApiKey as t}from"./apiKeyUtils.js";import{esriBasemapDefinitions as n}from"./basemapDefinitions.js";import{layerDefinitionEquals as i,layerToDefinition as a}from"./basemapUtils.js";const c=()=>s.getLogger("esri.support.basemapUtils");function f(){return{}}function l(e){for(const r in e){const s=e[r];s&&!s.destroyed&&s.destroy(),delete e[r]}}function p(r,s){let i;if("string"==typeof r){const o=r in n,a=!o&&r.includes("/");if(!o&&!a){if(t())c().warn(`Unable to find basemap definition for: ${r}. See available styles at https://developers.arcgis.com/rest/basemap-styles/`);else{const e=Object.entries(n).filter(([e,r])=>r.classic||r.is3d).map(([e])=>`"${e}"`).sort().join(", ");c().warn(`Unable to find basemap definition for: ${r}. Try one of these: ${e}`)}return null}s&&(i=s[r]),i||(i=o?e.fromId(r):new e({style:{id:r}}),s&&(s[r]=i))}else i=o(e,r);return i?.destroyed&&(c().warn("The provided basemap is already destroyed",{basemap:i}),i=null),i}function m(e,r=null){const s=p(e);if(!s)return null;const o=s.clone();return r&&(o.baseLayers=d(o.baseLayers,r.baseLayers),o.referenceLayers=d(o.referenceLayers,r.referenceLayers)),o}function d(e,s){const o=new r;return e.forEach(e=>{const r=s.find(r=>"scene"!==r.type&&i(a(e),a(r)))||e;o.includes(r)?o.push(e):o.push(r)}),o}export{p as basemapEnsureType,m as clonePreservingTiledLayers,f as createCache,l as destroyCache};
