import{__decorate as e}from"tslib";import{InvalidOperationError as r}from"../InvalidOperationError.js";import{applyJsonToLayer as t,layerToJson as i}from"../json/LayerJson.js";import{serializable as s}from"../support/Serializable.js";import{isWMSLayer as a}from"../utilities/_layers.js";import{checkArg as o}from"../utilities/checkArg.js";import{LayerExtension as l}from"./_LayerExtension.js";import{SublayerExtension as n}from"./_SublayerExtension.js";import{SublayerExtensionCollectionBase as y}from"./support/_SublayerExtensionCollection.js";const p="SublayerExtension collection for WMSLayerExtension is readonly";let u=class extends l{get layer(){return super.layer}get sublayerExtensions(){return super.sublayerExtensions}get wfsCapabilities(){return this._wfsCapabilities}get supportsSublayers(){return!0}get hasFeatures(){return!!this.layer?.featureInfoUrl}wfsUrl;_deferredSublayerProperties;_wfsCapabilities;_initializeWfsPromise;async initializeWfs(){return void 0===this._initializeWfsPromise&&(this._initializeWfsPromise=(async()=>{if(this.wfsUrl)try{this._wfsCapabilities||(this._wfsCapabilities=await(await import("@arcgis/core/layers/ogc/wfsUtils.js")).getCapabilities(this.wfsUrl))}catch(e){throw this._initializeWfsPromise=void 0,e}})()),this._initializeWfsPromise}get _layerView(){return this.layer&&this.mapExtension?._allLayerViews.find((e=>e.layer===this.layer))}_createSublayerExtension(e){return n.factory.create(e,"WMSSublayer")}_getProjectWebmapJSON(){const e=super._getProjectWebmapJSON();if(!e||this.dynamicallyAddedLayer)return e;const{visibleLayers:r,layers:t}=i(this.layer);return{...e,visibleLayers:r,layers:t}}async _onInitialize(){if(await super._onInitialize(),null==this.layer.imageFormat){const e=this.layer.resourceInfo?.supportedImageFormatTypes?.find((e=>e.includes("png")));this.layer.imageFormat=e??"png"}this._deferredSublayerProperties&&(await this.assignPropertiesAsync({layer:{layerType:"WMS",layers:this._deferredSublayerProperties}}),this._deferredSublayerProperties=void 0)}_isSupportedLayer(e){return a(e)}_createSublayerExtensionCollection(){return new f(this)}_getSerializableProperties(){const e=super._getSerializableProperties();return{...e,wfsUrl:"initial",layer:{...this._toPropertyDef(e.layer),default:{layerType:"WMS"},deserialize:r=>{const t=this._toPropertyDef(e.layer).deserialize(r);if(r&&!a(r)&&r.layers&&!this.layer?.sublayers){this._deferredSublayerProperties=this._deferredSublayerProperties||[];for(const e of r.layers){const r=this._deferredSublayerProperties.findIndex((r=>r.name===e.name));r>=0?this._deferredSublayerProperties[r]={...this._deferredSublayerProperties[r],...e}:this._deferredSublayerProperties.push({...e})}}return t}}}}async _applyPortalItemProperties(e){if("WMS"!==e.type)throw new Error(`Cannot create WMS layer from Portal item that has type: ${e.type}`);const r={layerType:"WMS",...await e.fetchData()};return t(r,this.layer)}};u=e([s],u);export{u as WMSLayerExtension};class f extends y{constructor(e){super(e,"layer.sublayers"),this._layerExtension=e}add(e,t){if(o("sublayerX",e).isNotMissing(),e.sublayer&&this._parent.layer.sublayers&&!this._parent.layer.sublayers.includes(e.sublayer))throw new r(p);return super.add(e,t)}removeAt(e){throw new r(p)}reorder(e,t){throw new r(p)}reverse(){throw new r(p)}sort(e){throw new r(p)}splice(e,t,...i){throw new r(p)}_createSublayerExtension(e){return this._parent._createSublayerExtension(e)}}