var e;import{__decorate as t}from"tslib";import r from"@arcgis/core/core/Collection";import{layerToJson as i}from"../json/LayerJson.js";import{serializable as a}from"../support/Serializable.js";import{notifyChange as s,watch as l}from"../support/observableUtils.js";import{ReadOnlyCollection as o}from"../utilities/ReadOnlyCollection.js";import{isImageryLayer as n}from"../utilities/_layers.js";import{getAllFieldInfos as p}from"../utilities/esri.js";import{LayerExtension as u,LayerExtensionSchema as d}from"./_LayerExtension.js";import{ArrayWrappedCollection as y}from"./support/ArrayWrappedCollection.js";import{PopupTemplateFeatureSettings as c}from"./support/PopupTemplateFeatureSettings.js";const h="Raster.";let f=class extends u{get hasFeatures(){return!0}get capabilities(){return this._layerCapabilities?this._layerCapabilities:this._capabilities()}get layer(){return super.layer}includeCatalogItems=!0;get hasRasterAttributeTable(){return this._hasRasterAttributeTable}get canChangeDefinitionExpression(){return!0}_layerCapabilities;_hasRasterAttributeTable;_getProjectWebmapJSON(){const e=super._getProjectWebmapJSON();if(!e||this.dynamicallyAddedLayer)return e;const{layerDefinition:t}=i(this.layer),{definitionExpression:r,drawingInfo:a}=t??{};return r&&(e.layerDefinition={...e.layerDefinition,definitionExpression:r}),a&&(e.layerDefinition={...e.layerDefinition,drawingInfo:a}),e}_getSerializableProperties(){const e=super._getSerializableProperties();return{...e,layer:{...this._toPropertyDef(e.layer),default:{layerType:"ArcGISImageServiceLayer"}},includeCatalogItems:{serializeModes:["initial"],default:!0}}}async _onInitialize(){await super._onInitialize();const e=await this.requestHelper.request(this.layer.url,{query:{f:"json"}});if(!e?.data)throw new Error(`Response to request for url ${this.layer.url} was invalid`);const{data:t}=e;if(t.capabilities){const e=t.capabilities.split(",").map((e=>e.trim()));this._layerCapabilities={supportsAdd:e.includes("Create"),supportsUpdate:e.includes("Update"),supportsDelete:e.includes("Delete"),supportsEditing:e.includes("Editing"),supportsQuery:e.includes("Catalog"),supportsStandardizedQueries:t.useStandardizedQueries,supportsAttachmentEditing:!1}}this._hasRasterAttributeTable=t.hasRasterAttributeTable}async _applyPortalItemProperties(e){if("Image Service"!==e.type)throw new Error(`Cannot create Imagery Layer from Portal item that has type: ${e.type}`);if(e.typeKeywords.includes("Elevation 3D Layer"))throw new Error("Cannot create Imagery Layer from Portal item that references an Elevation layer");e.url&&(this.layer.url=e.url)}_isSupportedLayer(e){return n(e)}_createSchema(){return new _(this)}_createFeatureSettings(){return new m(this)}};f=t([a],f);export{f as ImageryLayerExtension};let m=class extends c{get _defaultOutFields(){if(null==this.popupTemplate)return["*"];const e=p(this.popupTemplate),t=this.featureSource?.schema?.primaryKeyField;if(e&&t){return super._defaultOutFields.filter((e=>!e.startsWith(h)))}return["*"]}};m=t([a],m);let _=class extends d{static{e=this}static _loadStatusWatchKey="imagery-layer-schema-load-status-watch";_fieldsCollection;constructor(t){super(t),this._fieldsCollection=new o(new y({parent:t,targetProperty:"layer",arrayProperty:"fields"}),{destroyBackingCollection:!0}),s(this,"_fields"),this._handles.add(l(this._layerExtension,"layer.loadStatus",(()=>{"loaded"===this._layerExtension.layer?.loadStatus&&(s(this,"_fields"),this._handles.remove(e._loadStatusWatchKey))}),{sync:!0}),e._loadStatusWatchKey)}destroy(){this._fieldsCollection.destroy(),super.destroy()}get _fields(){return new o(this._fieldsCollection?.concat(this._rasterFields())??new r)}_getPropertyBindings(){return{primaryKeyField:{property:"objectIdField",readonly:!0},spatialReference:{property:"spatialReference",readonly:!0},geometryType:{value:"polygon"}}}_rasterFields(){const{layer:e}=this._layerExtension;return"loaded"!==this._layerExtension.layer?.loadStatus?new r:new r(e?.rasterFields?.filter((e=>e.name.startsWith(h))))}};_=e=t([a],_);