import e from"safe-stable-stringify";import{Warning as r}from"../support/_esriInternal.js";import{isCSVLayer as n,isFeatureLayer as i,isGeoJSONLayer as s,isMapImageSublayer as o,isPointCloudLayer as a,isSceneLayer as l,isStreamLayer as t}from"../utilities/_layers.js";import{checkArg as p}from"../utilities/checkArg.js";import{LabelingInfo as f}from"./LabelingInfo.js";import{PointCloudRenderer as d}from"./PointCloudRenderer.js";import{Renderer as b}from"./Renderer.js";export var DrawingInfo;!function(y){y.applyToEsriApiLayer=async function(e,y){if(p("json",e).isNotMissing(),p("layer",y).isNotMissing(),(i(y)||l(y)||n(y)||t(y)||s(y)||o(y))&&(e.hasOwnProperty("labelingInfo")&&e.labelingInfo&&(y.labelingInfo=[],e.labelingInfo.forEach((e=>{y.labelingInfo.push(f.toEsriApiLabelClass(e))}))),e.hasOwnProperty("showLabels")&&null!=e.showLabels&&(y.labelsVisible=e.showLabels)),e.hasOwnProperty("renderer")){let n=!0;if(e.renderer)if(a(y))y.renderer=await d.toEsriApiPointCloudRenderer(e.renderer);else{const r=b.toEsriApiRenderer(e.renderer);r?y.renderer=r:n=!1}else y.renderer=void 0;n||y.loadWarnings.push(new r("renderer:unsupported",`Renderers of type '${e.renderer?.type??"unknown"}' are not supported`,{definition:e.renderer}))}e.hasOwnProperty("transparency")&&null!=e.transparency&&(y.opacity=1-e.transparency/100)},y.fromEsriApiLayer=function(r){p("layer",r).isNotMissing();const n={};if(o(r)&&!r.layer?.capabilities?.exportMap?.supportsDynamicLayers)return n;if(r.renderer)if(o(r)){const i=r.sourceJSON?.drawingInfo?.renderer;"map-layer"===r.source.type&&i&&e(r.renderer?.toJSON())===e(b.toEsriApiRenderer(i)?.toJSON())||(n.renderer=b.fromEsriApiRenderer(r.renderer))}else n.renderer=b.fromEsriApiRenderer(r.renderer);return void 0!==r.opacity&&o(r)&&(n.transparency=100*(1-r.opacity)),r.labelingInfo?.length&&(n.labelingInfo=[],r.labelingInfo.forEach((e=>{const r=f.fromEsriApiLabelClass(e);r.labelExpression&&r.labelExpressionInfo&&delete r.labelExpressionInfo,n.labelingInfo.push(r)}))),void 0!==r.labelsVisible&&null!==r.labelsVisible&&(n.showLabels=r.labelsVisible),n}}(DrawingInfo||(DrawingInfo={}));