import{checkArg as s}from"../utilities/checkArg.js";import{ERR_LAYER_TYPE_MISMATCH as r,applyLayerBaseToEsriApiLayer as e,applyOperationalLayerToEsriApiLayer as i,fromEsriApiLayerToLayerBase as l,fromEsriApiLayerToOperationalLayer as a}from"./_layerHelper.js";export var KMLLayer;!function(y){async function o(l,a){if(s("layerJson",l).isNotMissing(),s("layerJson.layerType",l.layerType).satisfies((s=>!s||"KML"===s),r),s("layer",a).isNotMissing(),e(l,a),i(l,a),l.hasOwnProperty("visibleFolders")&&null!=l.visibleFolders&&a.sublayers){const s=r=>{r.forEach((r=>{r.visible=l.visibleFolders.includes(r.id),r.sublayers&&s(r.sublayers)}))};s(a.sublayers)}l.hasOwnProperty("url")&&(a.url=l.url)}y.toEsriApiKMLLayer=async function(e){s("layerJson",e).isNotMissing(),s("layerJson.layerType",e.layerType).satisfies((s=>!s||"KML"===s),r);const i=new((await import("@arcgis/core/layers/KMLLayer")).default);return await o(e,i),i},y.applyToEsriApiKMLLayer=o,y.fromEsriApiKMLLayer=function(r){s("layer",r).isNotMissing();const e={...l(r),...a(r),layerType:"KML"};if(r.sublayers){e.visibleFolders=[];const s=r=>{r.forEach((r=>{r.visible&&e.visibleFolders.push(r.id),r.sublayers&&s(r.sublayers)}))};s(r.sublayers)}return r.url&&(e.url=r.url),e}}(KMLLayer||(KMLLayer={}));