import{__decorate as e}from"tslib";import{ArgumentError as r}from"../ArgumentError.js";import{InvalidOperationError as t}from"../InvalidOperationError.js";import{_isGraphicsLayerJson as a}from"../json/FeatureLayerJson.js";import{applyJsonToLayer as o}from"../json/LayerJson.js";import{serializable as i}from"../support/Serializable.js";import{FeatureLayerExtensionBase as s}from"./FeatureLayerExtensionBase.js";const p="Cannot use feature layer that has a url and no source collection.",l=Object.freeze({supportsAdd:!1,supportsUpdate:!1,supportsDelete:!1,supportsEditing:!1,supportsQuery:!0,supportsAttachmentEditing:!1,supportsStandardizedQueries:!0});export const FEATURE_COLLECTION_LAYER_TYPE="feature-collection-layer";let n=class extends s{constructor(e){const r=e&&e.layer;r?.$ref&&delete r.featureCollection,super(e)}_getSerializableProperties(){const e=super._getSerializableProperties();return{...e,layer:{...this._toPropertyDef(e.layer),default:{layerType:"ArcGISFeatureLayer",featureCollection:{layers:[{featureSet:{geometryType:"esriGeometryPoint",features:[]}}]}}}}}_isSupportedLayer(e){return super._isSupportedLayer(e)&&!e.url}_getSerializableLayerType(){return"feature-collection-layer"}async _onInitialize(){if(await super._onInitialize(),!this._isSupportedLayer(this.layer))throw new t(p)}_applyLayerProperties(e,t){if(e.url)throw new r(p);return super._applyLayerProperties(e,t)}async _applyPortalItemProperties(e){if("Feature Collection"!==e.type)throw new Error(`Cannot create Feature Layer from Portal item that has type: ${e.type}`);const r=await e.fetchData();if(a({layerType:"ArcGISFeatureLayer",featureCollection:r}))throw new Error("Cannot create Feature Layer from Portal item that contains a graphics layer feature collection");return o({layerType:"ArcGISFeatureLayer",featureCollection:r},this.layer)}_capabilities(){return l}};n=e([i],n);export{n as FeatureCollectionLayerExtension};