import{__decorate as e}from"tslib";import t from"@arcgis/core/layers/support/CodedValueDomain";import r from"@arcgis/core/popup/ExpressionInfo";import i from"@arcgis/core/popup/FieldInfo";import{serializable as s}from"../support/Serializable.js";import{notifyChange as a,watch as n}from"../support/observableUtils.js";import{ReadOnlyCollection as o}from"../utilities/ReadOnlyCollection.js";import{isPointCloudLayer as l}from"../utilities/_layers.js";import{LayerExtension as p,LayerExtensionSchema as u}from"./_LayerExtension.js";import{ArrayWrappedCollection as d}from"./support/ArrayWrappedCollection.js";import{PopupTemplateFeatureSettings as f}from"./support/PopupTemplateFeatureSettings.js";import{addOutFields as m}from"./support/layers.js";let c=class extends p{_enableClientSideData;get layer(){return super.layer}get _layerView(){return this.layer&&this.mapExtension?._allLayerViews.find((e=>e.layer===this.layer))}get hasFeatures(){return!0}get enableClientSideData(){return this._enableClientSideData}set enableClientSideData(e){this._enableClientSideData=e,this._updateClientSideFields()}get canChangeOpacity(){return!1}_getProjectWebmapJSON(){const e=super._getProjectWebmapJSON();return e&&delete e.opacity,e}async _onInitialize(){await super._onInitialize(),this._updateClientSideFields(),n(this,"layer",(()=>{this._updateClientSideFields()}),{sync:!0})}async _postInitialize(){await super._postInitialize(),await this._setDecodedPopupFieldInfos()}_getSerializableProperties(){const e=super._getSerializableProperties();return{...e,layer:{...this._toPropertyDef(e.layer),default:{layerType:"PointCloudLayer"}},enableClientSideData:{serializeModes:["initial"],default:!0}}}_isSupportedLayer(e){return l(e)}_createSchema(){return new _(this)}_createFeatureSettings(){return new f(this)}_updateClientSideFields(){this.layer&&this._enableClientSideData&&m(this.layer,this.featureSettings.outFields)}_updateFieldExpressions(e,t){if(this.schema.fields.some((t=>t.name===e))){const s=this.featureSettings.popupTemplate.fieldInfos?.find((t=>t.fieldName===e));if(!s)return;s.visible=!1,this.featureSettings.popupTemplate.fieldInfos=[...this.featureSettings.popupTemplate.fieldInfos,new i({fieldName:`expression/__gcx-${e.toLowerCase()}`})],this.featureSettings.popupTemplate.expressionInfos=[...this.featureSettings.popupTemplate.expressionInfos,new r({expression:t,name:`__gcx-${e.toLowerCase()}`,returnType:"string",title:e})]}}async _setDecodedPopupFieldInfos(){const e=this.schema.fields.find((e=>"CLASS_CODE"===e.name));if(e){const r=await this.layer.queryCachedStatistics("CLASS_CODE"),i=r?.labels?.labels;i&&(e.domain=new t({codedValues:i.map((e=>({code:e.value,name:e.label})))}))}null==this.featureSettings.popupTemplate.expressionInfos&&(this.featureSettings.popupTemplate.expressionInfos=[]);this._updateFieldExpressions("RGB","var rgb = $feature.RGB; var red = Floor(rgb/65536,0); var green = Floor((rgb-(red*65536))/256,0); var blue = rgb-(red*65536)-(green*256); return 'rgb(' + red + ',' + green + ',' + blue + ')';");this._updateFieldExpressions("RETURNS","var returnnumber = $feature.RETURNS % 16; var numberofreturns = Floor($feature.RETURNS / 16); return returnnumber + ' / ' + numberofreturns;")}};c=e([s],c);export{c as PointCloudLayerExtension};let _=class extends u{_fieldCollection;constructor(e){super(e),this._fieldCollection=new o(new d({parent:e,targetProperty:"layer",arrayProperty:"fields"})),a(this,"_fields")}get _fields(){return this._fieldCollection}_getPropertyBindings(){return{spatialReference:{property:"spatialReference",readonly:!0}}}};_=e([s],_);