import{__decorate as e}from"tslib";import{applyJsonToLayer as r,layerToJson as t}from"../json/LayerJson.js";import{serializable as a}from"../support/Serializable.js";import{isMapImageLayer as i}from"../utilities/_layers.js";import{LayerExtension as s,LayerExtensionSchema as n}from"./_LayerExtension.js";import{SublayerExtension as o}from"./_SublayerExtension.js";let y=class extends s{get layer(){return super.layer}get sublayerExtensions(){return super.sublayerExtensions}get supportsSublayers(){return!0}get sublayersAreReadOnly(){const e=this.layer?.capabilities;return!e||!e.exportMap.supportsDynamicLayers}_getProjectWebmapJSON(){const e=super._getProjectWebmapJSON();if(!e||this.dynamicallyAddedLayer)return e;const{visibleLayers:r,layers:a}=t(this.layer);return e.visibleLayers=r,a&&(e.layers=a.map((e=>{const{id:r,layerDefinition:t,parentLayerId:a}=e,i={id:r,parentLayerId:a},{definitionExpression:s,drawingInfo:n}=t??{};return s&&(i.layerDefinition={...i.layerDefinition,definitionExpression:s}),n&&this.layer?.capabilities?.exportMap?.supportsDynamicLayers&&(i.layerDefinition={...i.layerDefinition,drawingInfo:n}),i}))),e}_createSublayerExtension(e){return o.factory.create(e,"ArcGISMapServiceSublayer")}_getSerializableProperties(){const e=super._getSerializableProperties();return{...e,layer:{...this._toPropertyDef(e.layer),default:{layerType:"ArcGISMapServiceLayer"}}}}_isSupportedLayer(e){return i(e)}_createSchema(){return new l(this)}async _applyPortalItemProperties(e){if("Map Service"!==e.type)throw new Error(`Cannot create Map Image Layer from Portal item that has type: ${e.type}`);if(e.typeKeywords.includes("Tiled"))throw new Error("Cannot create Map Image Layer from Portal item that references Tile Map Service");const t={layerType:"ArcGISMapServiceLayer",url:e.url},a=await e.fetchData();return a?.layers&&(t.layers=a.layers),r(t,this.layer)}};y=e([a],y);export{y as MapImageLayerExtension};let l=class extends n{_getPropertyBindings(){return{spatialReference:{property:"spatialReference",readonly:!0}}}};l=e([a],l);