import e from"@arcgis/core/portal/Portal";import r from"@arcgis/core/portal/PortalItem";import{isSceneLayer as i}from"../utilities/_layers.js";import{checkArg as s}from"../utilities/checkArg.js";import{isNumeric as a}from"../utilities/number.js";import{LayerDefinition as p}from"./LayerDefinition.js";import{PopupInfo as l}from"./PopupInfo.js";import{ERR_LAYER_TYPE_MISMATCH as o,applyLayerBaseToEsriApiLayer as t,applyOperationalLayerToEsriApiLayer as n,fromEsriApiLayerToLayerBase as y,fromEsriApiLayerToOperationalLayer as c}from"./_layerHelper.js";export var SceneLayer;!function(u){async function f(a,y,c){s("layerJson",a).isNotMissing(),s("layerJson.layerType",a.layerType).satisfies((e=>!e||"ArcGISSceneServiceLayer"===e),o),s("layer",y).isNotMissing().satisfies(i,o),t(a,y),n(a,y),a.hasOwnProperty("url")&&(y.url=a.url),a.hasOwnProperty("itemId")&&(y.portalItem?y.portalItem.id=a.itemId:y.portalItem=new r({id:a.itemId,portal:c||e.getDefault()})),a.hasOwnProperty("popupInfo")&&null!=a.popupInfo&&(y.popupTemplate=l.toEsriApiPopupTemplate(a.popupInfo)),a.hasOwnProperty("screenSizePerspective")&&null!=a.screenSizePerspective&&(y.screenSizePerspectiveEnabled=a.screenSizePerspective),a.hasOwnProperty("showLabels")&&null!=a.showLabels&&(y.labelsVisible=a.showLabels),a.hasOwnProperty("disablePopup")&&(y.popupEnabled=!a.disablePopup),a.hasOwnProperty("layerDefinition")&&null!=a.layerDefinition&&await p.applyToEsriApiLayer(a.layerDefinition,y)}u.esriSceneLayerDefaults={labelsVisible:!0,legendEnabled:!0,popupEnabled:!0,visible:!0,opacity:1,screenSizePerspective:!0},u.toEsriApiLayer=async function(e,r){s("layerJson",e).isNotMissing(),s("layerJson.layerType",e.layerType).satisfies((e=>!e||"ArcGISSceneServiceLayer"===e),o);const i=new((await import("@arcgis/core/layers/SceneLayer")).default);return await f(e,i,r),i},u.applyToEsriApiLayer=f,u.fromEsriApiSceneLayer=function(e){s("layer",e).isNotMissing();const r={...y(e,u.esriSceneLayerDefaults),...c(e),layerType:"ArcGISSceneServiceLayer",url:a(e.layerId)?`${e.url}/layers/${e.layerId}`:e.url??void 0,layerDefinition:p.fromEsriApiLayer(e,u.esriSceneLayerDefaults)};return e.portalItem&&(r.itemId=e.portalItem.id??void 0),e.popupTemplate&&(r.popupInfo=l.fromEsriApiPopupTemplate(e.popupTemplate)),e.screenSizePerspectiveEnabled!==u.esriSceneLayerDefaults.screenSizePerspective&&(r.screenSizePerspective=e.screenSizePerspectiveEnabled),e.labelsVisible!==u.esriSceneLayerDefaults.labelsVisible&&(r.showLabels=e.labelsVisible),e.popupEnabled!==u.esriSceneLayerDefaults.popupEnabled&&(r.disablePopup=!e.popupEnabled),r}}(SceneLayer||(SceneLayer={}));