import{WellKnownBasemap as e,wellKnownBasemapTitles as a}from"../support/esri.js";import{basemapsAreEquivalent as s,isLayerWithLegendEnabledProperty as r,standardBasemaps as i}from"../utilities/_layers.js";import{checkArg as t}from"../utilities/checkArg.js";import{LayerBase as o}from"./LayerBase.js";export var BaseMap;function n(e){const a=o.fromEsriApiLayer(e);return r(e)&&(a.showLegend=e.legendEnabled),delete a.listMode,delete a.refreshInterval,a}!function(r){async function p(e,a,s){t("json",e).isNotMissing(),t("basemap",a).isNotMissing(),e.hasOwnProperty("title")&&null!=e.title&&(a.title=e.title);const r=e.baseMapLayers?.filter((e=>!e.path));r&&(await o.applyToEsriApiLayers(a.baseLayers,r.filter((e=>!e.isReference)),s),await o.applyToEsriApiLayers(a.referenceLayers,r.filter((e=>e.isReference)),s))}r.toEsriApiBasemap=async function(r,o){t("json",r).isNotMissing();const n={baseMapLayers:[],...r},l=(await import("@arcgis/core/Basemap")).default,c=new l,f=Object.values(e).find((e=>s(i[e],n)));if(f){let s;switch(f){case e.HYBRID_VECTOR:case e.TERRAIN_VECTOR:case e.OCEANS_VECTOR:case e.OPEN_STREET_MAP_VECTOR:s=l.fromId(f.replace("-vector",""));break;default:s=l.fromId(f)}c.id=f,c.title=a[f],c.thumbnailUrl=s?.thumbnailUrl}return await p(n,c,o),c},r.applyToEsriApiBasemap=p,r.fromEsriApiBasemap=function(e){return t("basemap",e).isNotMissing(),{title:e.title,baseMapLayers:e.baseLayers.toArray().map(n).concat(e.referenceLayers.toArray().map((e=>({...n(e),isReference:!0}))))}}}(BaseMap||(BaseMap={}));