import e from"@arcgis/core/Basemap";import t from"@arcgis/core/portal/Portal.js";import{basemapHas3DLayers as a,createStandardBasemap as o,getStandardBasemapId as r}from"../utilities/basemaps.js";import{}from"./BasemapLayerJson.js";import{applyJsonToLayers as i}from"./LayerJson.js";export async function jsonToBasemap(i){const s=r(i);if(s){const e=await o(s);return e.id=i.id??e.id,e.title=i.title??e.title,e}{const o=a(i);return e.fromJSON(i,o?{origin:"web-scene",portal:t.getDefault()}:{origin:"web-map"})}}export async function applyJsonToBasemap(e,t){t.loaded||await t.load(),e.hasOwnProperty("title")&&null!=e.title&&(t.title=e.title);const a=[],o=[];e.baseMapLayers?.forEach((e=>{e.path||(e.isReference?o:a).push(e)})),(a.length||o.length)&&(await i(a,t.baseLayers),await i(o,t.referenceLayers))}export function basemapToJson(e){return e?a(e)?e.write({},{origin:"web-scene",portal:t.getDefault()}):e.toJSON():{}}