import{isCSVLayer as e}from"../utilities/_layers.js";import{checkArg as i}from"../utilities/checkArg.js";import{LayerDefinition as r}from"./LayerDefinition.js";import{PopupInfo as l}from"./PopupInfo.js";import{defaultPointRenderer as n}from"./Renderer.js";import{ERR_LAYER_TYPE_MISMATCH as o,applyLayerBaseToEsriApiLayer as a,applyOperationalLayerToEsriApiLayer as t,fromEsriApiLayerToLayerBase as s,fromEsriApiLayerToOperationalLayer as p}from"./_layerHelper.js";export var CSVLayer;!function(y){async function u(n,s){i("layerJson",n).isNotMissing(),i("layerJson.layerType",n.layerType).satisfies((e=>!e||"CSV"===e),o),i("layer",s).isNotMissing().satisfies(e,o),a(n,s),t(n,s),n.hasOwnProperty("columnDelimiter")&&null!=n.columnDelimiter&&(s.delimiter=n.columnDelimiter),n.hasOwnProperty("locationInfo")&&null!=n.locationInfo&&(n.locationInfo.hasOwnProperty("latitudeFieldName")&&(s.latitudeField=n.locationInfo.latitudeFieldName),n.locationInfo.hasOwnProperty("longitudeFieldName")&&(s.longitudeField=n.locationInfo.longitudeFieldName)),n.hasOwnProperty("popupInfo")&&null!=n.popupInfo&&(s.popupTemplate=l.toEsriApiPopupTemplate(n.popupInfo)),n.hasOwnProperty("screenSizePerspective")&&null!=n.screenSizePerspective&&(s.screenSizePerspectiveEnabled=n.screenSizePerspective),n.hasOwnProperty("showLabels")&&null!=n.showLabels&&(s.labelsVisible=n.showLabels),n.hasOwnProperty("url")&&(s.url=n.url),n.hasOwnProperty("layerDefinition")&&null!=n.layerDefinition&&await r.applyToEsriApiLayer(n.layerDefinition,s)}y.esriCSVLayerDefaults={labelsVisible:!0,legendEnabled:!0,popupEnabled:!0,visible:!0,opacity:1,minScale:0,maxScale:0,screenSizePerspective:!0},y.toEsriApiLayer=async function(e){i("layerJson",e).isNotMissing(),i("layerJson.layerType",e.layerType).satisfies((e=>!e||"CSV"===e),o);const r=new((await import("@arcgis/core/layers/CSVLayer")).default);return function(e){e.layerDefinition=e.layerDefinition||{},e.layerDefinition.drawingInfo=e.layerDefinition.drawingInfo||{},e.layerDefinition.drawingInfo.renderer=e.layerDefinition.drawingInfo.renderer||n}(e),await u(e,r),r},y.applyToEsriApiLayer=u,y.fromEsriApiCSVLayer=function(e){i("layer",e).isNotMissing();const n={...s(e,y.esriCSVLayerDefaults),...p(e),layerType:"CSV",layerDefinition:r.fromEsriApiLayer(e,y.esriCSVLayerDefaults),url:e.url??void 0};return e.popupTemplate&&(n.popupInfo=l.fromEsriApiPopupTemplate(e.popupTemplate)),e.screenSizePerspectiveEnabled!==y.esriCSVLayerDefaults.screenSizePerspective&&(n.screenSizePerspective=e.screenSizePerspectiveEnabled),e.labelsVisible!==y.esriCSVLayerDefaults.labelsVisible&&(n.showLabels=e.labelsVisible),n.columnDelimiter=e.delimiter,e.latitudeField&&e.longitudeField&&(n.locationInfo={locationType:"coordinates"},n.locationInfo.latitudeFieldName=e.latitudeField,n.locationInfo.longitudeFieldName=e.longitudeField),n}}(CSVLayer||(CSVLayer={}));