import{__decorate as e}from"tslib";import r from"@arcgis/core/config";import t from"@arcgis/core/core/Collection";import i from"@arcgis/core/geometry/SpatialReference";import a from"@arcgis/core/layers/support/Field";import{InvalidOperationError as s}from"../InvalidOperationError.js";import{Schema as l}from"../data/Schema.js";import{layerToJson as n}from"../json/LayerJson.js";import{translate as o}from"../locale/language.js";import{serializable as p}from"../support/Serializable.js";import{notifyChange as y}from"../support/observableUtils.js";import{ReadOnlyCollection as c}from"../utilities/ReadOnlyCollection.js";import{isKMLLayer as m}from"../utilities/_layers.js";import{checkArg as u}from"../utilities/checkArg.js";import{toAbsoluteUri as d}from"../utilities/uri.js";import{LayerExtension as b}from"./_LayerExtension.js";import{SublayerExtension as h}from"./_SublayerExtension.js";import{SublayerExtensionCollectionBase as g}from"./support/_SublayerExtensionCollection.js";export const DEFAULT_KML_UTILITY="https://utility.arcgis.com/sharing/kml";const _="SublayerExtension collection for KMLLayerExtension is readonly";let f=class extends b{get layer(){return super.layer}get sublayerExtensions(){return super.sublayerExtensions}get supportsSublayers(){return!0}get hasFeatures(){return!0}get _layerView(){return this.layer&&this.mapExtension?._allLayerViews.find((e=>e.layer===this.layer))}get _layerSupportsHideChildren(){return!1}get _graphics(){return this._layerView?this._layerView.allVisiblePoints.concat(this._layerView.allVisiblePolygons).concat(this._layerView.allVisiblePolylines).toArray():[]}_createSublayerExtension(e){return h.factory.create(e,"KMLSublayer")}_getProjectWebmapJSON(){const e=super._getProjectWebmapJSON();if(!e||this.dynamicallyAddedLayer)return e;const{visibleFolders:r}=n(this.layer);return e.visibleFolders=r,e}async _applyPortalItemProperties(e){if("KML"!==e.type)throw new Error(`Cannot create KML Layer from Portal item that has type: ${e.type}`);this.layer.url=e.url??d("data",`${e.itemUrl}/`)}_capabilities(){return{...super._capabilities(),supportsStandardizedQueries:!0}}_getSerializableProperties(){const e=super._getSerializableProperties();return{...e,layer:{...this._toPropertyDef(e.layer),default:{layerType:"KML"}}}}_createSchema(){return new S}_isSupportedLayer(e){return m(e)}async _initializeLayer(){r.kmlServiceUrl||(r.kmlServiceUrl=DEFAULT_KML_UTILITY)}_createSublayerExtensionCollection(){return new w(this)}};f=e([p],f);export{f as KMLLayerExtension};class w extends g{_layerExtension;constructor(e){super(e,"layer.sublayers"),this._layerExtension=e}add(e,r){if(u("sublayerX",e).isNotMissing(),e.sublayer&&this._parent.layer.sublayers&&!this._parent.layer.sublayers.includes(e.sublayer))throw new s(_);return super.add(e,r)}removeAt(e){throw new s(_)}reorder(e,r){throw new s(_)}reverse(){throw new s(_)}sort(e){throw new s(_)}splice(e,r,...t){throw new s(_)}_createClone(){return new w(this._layerExtension)}_createSublayerExtension(e){return this._parent._createSublayerExtension(e)}}const x="This schema property is read-only.";let S=class extends l{_fieldCollection;constructor(){super(),this._fieldCollection=this._createFieldCollection(),y(this,"_fields")}get spatialReference(){return i.WGS84}set spatialReference(e){throw new s(x)}get primaryKeyField(){return"id"}set primaryKeyField(e){throw new s(x)}get _fields(){return this._fieldCollection}_createFieldCollection(){const e=new t;return e.add(new a({name:"id",alias:o("gcx.api.mapping.kml-sublayer-extension.schema.id"),editable:!1,type:"oid"})),e.add(new a({name:"name",alias:o("gcx.api.mapping.kml-sublayer-extension.schema.name"),editable:!1,type:"string"})),e.add(new a({name:"description",alias:o("gcx.api.mapping.kml-sublayer-extension.schema.description"),editable:!1,type:"string"})),e.add(new a({name:"visibility",alias:o("gcx.api.mapping.kml-sublayer-extension.schema.visibility"),editable:!1,type:"integer"})),e.add(new a({name:"balloonStyleText",alias:o("gcx.api.mapping.kml-sublayer-extension.schema.balloonStyleText"),editable:!1,type:"string"})),e.add(new a({name:"styleUrl",alias:o("gcx.api.mapping.kml-sublayer-extension.schema.styleUrl"),editable:!1,type:"string"})),new c(e)}};S=e([p],S);