import{__decorate as e}from"tslib";import t from"@arcgis/core/core/Collection";import{layerToJson as r}from"../json/LayerJson.js";import{serializable as i}from"../support/Serializable.js";import{notifyChange as a,watch as s}from"../support/observableUtils.js";import{ReadOnlyCollection as l}from"../utilities/ReadOnlyCollection.js";import{isImageryLayer as o}from"../utilities/_layers.js";import{getAllFieldInfos as n}from"../utilities/esri.js";import{LayerExtension as p,LayerExtensionSchema as u}from"./_LayerExtension.js";import{ArrayWrappedCollection as y}from"./support/ArrayWrappedCollection.js";import{PopupTemplateFeatureSettings as d}from"./support/PopupTemplateFeatureSettings.js";const c="Raster.";let f=class extends p{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}=r(this.layer),{definitionExpression:i,drawingInfo:a}=t??{};return i&&(e.layerDefinition={...e.layerDefinition,definitionExpression:i}),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 o(e)}_createSchema(){return new h(this)}_createFeatureSettings(){return new m(this)}};f=e([i],f);export{f as ImageryLayerExtension};let m=class extends d{get _defaultOutFields(){if(null==this.popupTemplate)return["*"];const e=n(this.popupTemplate),t=this.featureSource?.schema?.primaryKeyField;if(e&&t){return super._defaultOutFields.filter((e=>!e.startsWith(c)))}return["*"]}};m=e([i],m);let h=class extends u{_fieldsCollection;constructor(e){super(e),this._fieldsCollection=new l(new y({parent:e,targetProperty:"layer",arrayProperty:"fields"})),a(this,"_fields");const t=s(this._layerExtension,"layer.loadStatus",(()=>{"loaded"===this._layerExtension.layer?.loadStatus&&(a(this,"_fields"),t.remove())}),{sync:!0})}get _fields(){return new l(this._fieldsCollection?.concat(this._rasterFields())??new t)}_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 t:new t(e?.rasterFields?.filter((e=>e.name.startsWith(c))))}};h=e([i],h);