import{isBuildingComponentSublayer as r,isBuildingGroupSublayer as a,isWMSSublayer as e}from"../utilities/layers.js";import{layerToJson as i}from"./LayerJson.js";export async function jsonToSublayer(r,a){return"WMS"===a?(await import("../portal/WMSSublayer.js")).WMSSublayer.toEsriApiWMSSublayer(r):(await import("../portal/Layer.js")).Layer.toEsriApiSublayer(r,a)}export async function applyJsonToSublayer(i,t){i&&Object.keys(i).some((r=>"$ref"!==r&&"$sublayerType"!==r))&&(e(t)?await(await import("../portal/WMSSublayer.js")).WMSSublayer.applyToEsriApiWMSSublayer(i,t):r(t)||a(t)?await(await import("../portal/BuildingSceneSublayer.js")).BuildingSceneSublayer.applyToEsriApiBuildingSublayer(i,t):await(await import("../portal/Layer.js")).Layer.applyToEsriApiSublayer(i,t))}export function sublayerToJson(r){const{layer:a}=r;if(a){const e=i(a);if(null!=e?.layers)return e.layers.find((a=>a.id===r.id))}return r.write({},{layerContainerType:"operational-layers",origin:"web-map",writeSublayerStructure:!0})}