import{isCSVLayer as e,isElevationLayer as i,isFeatureLayer as a,isLayerWithLegendEnabledProperty as r,isStreamLayer as t,isSubtypeSublayer as l}from"../utilities/_layers.js";import{checkArg as s}from"../utilities/checkArg.js";export const ERR_LAYER_TYPE_MISMATCH="Layer type mismatch";export function applyLayerBaseToEsriApiLayer(e,a){if(s("layerJson",e).isNotMissing(),s("layer",a).isNotMissing(),e.hasOwnProperty("id")&&!l(a)&&null!=e.id&&(a.id=e.id),e.hasOwnProperty("visibility")&&null!=e.visibility&&(a.visible=e.visibility),e.hasOwnProperty("opacity")&&null!=e.opacity&&(a.opacity=e.opacity),i(a)||(e.hasOwnProperty("maxScale")&&(a.maxScale=e.maxScale),e.hasOwnProperty("minScale")&&(a.minScale=e.minScale)),e.hasOwnProperty("showLegend"))try{r(a)&&null!=e.showLegend&&(a.legendEnabled=e.showLegend)}catch{}e.hasOwnProperty("title")&&(a.title=e.title),e.hasOwnProperty("blendMode")&&(a.blendMode=e.blendMode)}export function applyBasemapLayerToEsriApiLayer(e,i){s("layerJson",e).isNotMissing(),s("layer",i).isNotMissing()}export function applyOperationalLayerToEsriApiLayer(e,i){s("layerJson",e).isNotMissing(),s("layer",i).isNotMissing(),e.hasOwnProperty("refreshInterval")&&(i.refreshInterval=e.refreshInterval),e.hasOwnProperty("listMode")&&null!=e.listMode&&(i.listMode=e.listMode)}export function fromEsriApiLayerToLayerBase(i,r={}){s("layer",i).isNotMissing();const n=l(i)?{}:{id:i.id};if(n.visibility=i.visible,i.opacity!==r.opacity&&(n.opacity=i.opacity),!a(i)||e(i)||t(i)){const{maxScale:e,minScale:a}=i;null==e||isNaN(e)||e===r.maxScale&&e===a||(n.maxScale=e),null==a||isNaN(a)||a===r.minScale&&a===e||(n.minScale=a)}return"boolean"==typeof i.legendEnabled&&i.legendEnabled!==r.legendEnabled&&(n.showLegend=i.legendEnabled),n.title=i.title??void 0,n.blendMode=i.blendMode,n}export function fromEsriApiLayerToOperationalLayer(e){s("layer",e).isNotMissing();const i={};return"refreshInterval"in e&&(i.refreshInterval=e.refreshInterval),e.listMode&&(i.listMode=e.listMode),i}