import{__decorate as e}from"tslib";import{InvalidOperationError as r}from"../InvalidOperationError.js";import{applyJsonToLayer as t}from"../json/LayerJson.js";import{DefaultArcGISRequestHelper as a}from"../support/ArcGISRequestHelper.js";import{serializable as i}from"../support/Serializable.js";import{isTileLayer as s}from"../utilities/_layers.js";import{checkArg as o}from"../utilities/checkArg.js";import{LayerExtension as l,LayerExtensionLayerListSettings as n,LayerExtensionSchema as y}from"./_LayerExtension.js";import{SublayerExtension as p}from"./_SublayerExtension.js";let c=class extends l{get layer(){return super.layer}get supportsSublayers(){return!0}_createSublayerExtension(e){return p.factory.create(e,"ArcGISTiledSublayer")}_applyLayerProperties(e,r){o("layerJson",e).isNotMissing();const a=e.layerType||e.type;return o("layerJson.layerType",a).satisfies((e=>!e||"ArcGISTiledMapServiceLayer"===e)),o("layer",r).isNotMissing().satisfies((e=>this._isSupportedLayer(e))),t(e,r)}_createLayerListSettings(e){return new n(e,this,!1)}_getSerializableProperties(){const e=super._getSerializableProperties();return{...e,layer:{...this._toPropertyDef(e.layer),default:{layerType:"ArcGISTiledMapServiceLayer"}}}}_isSupportedLayer(e){return s(e)}_createSchema(){return new u(this)}async _initializeLayer(){if(await super._initializeLayer(),!this.layer.url)throw new r("Tile layer must have a URL.")}async _onInitialize(){if(await super._onInitialize(),!this.layer.tileInfo)throw new Error(`The layer at URL "${this.layer.url}" is not a tile layer or does not have a tiling scheme defined.`)}async _applyPortalItemProperties(e){if("Map Service"!==e.type)throw new Error(`Cannot create Tile Layer from Portal item that has type: ${e.type}`);const r=await l._getLayerData(e.url,new a);if("Elevation"===r.cacheType)throw new Error("Cannot create Tile Layer from Portal item that references an Elevation layer");if(!r.tileInfo)throw new Error("Cannot create Tile Layer from Portal item that does not reference a tiled map service");this.layer.url=e.url||this.layer.url}};c=e([i],c);export{c as TileLayerExtension};let u=class extends y{_getPropertyBindings(){return{spatialReference:{property:"spatialReference",readonly:!0}}}};u=e([i],u);