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