import{__decorate as e}from"tslib";import{generateId as r}from"../Entity.js";import{_isGraphicsLayerJson as t,GRAPHICS_LAYER_ID as a}from"../json/FeatureLayerJson.js";import{applyJsonToLayer as s}from"../json/LayerJson.js";import{serializable as i}from"../support/Serializable.js";import{watch as o}from"../support/observableUtils.js";import{isGraphicsLayer as l}from"../utilities/_layers.js";import{checkArg as p}from"../utilities/checkArg.js";import{LayerExtension as n}from"./_LayerExtension.js";export const GRAPHICS_LAYER_TYPE="graphics-layer";let y=class extends n{get hasFeatures(){return!0}get layer(){return super.layer}constructor(e){super(e),this.layer&&this.layer._fields&&this.schema?.fields&&(this.schema.fields.removeAll(),this.schema.fields.addMany(this.layer._fields))}async _onInitialize(){return this._handles.add(o(this,"layer",(e=>{e._fields&&this.schema?.fields&&(this.schema.fields.removeAll(),this.schema.fields.addMany(e._fields))}))),super._onInitialize()}_applyLayerProperties(e,r){return e.hasOwnProperty("featureCollection")&&p("layerJson",e).satisfies(t),super._applyLayerProperties(e,r)}async*_getFeatures(e,r){const t=this.schema.primaryKeyField;if(!t)return;const a=this.layer.graphics.filter((r=>e.includes(r.attributes[t]))),{toFeature:s}=await import("../data/Feature.js");yield*a.map((e=>s(e,{source:this}))).toArray()}_getSerializableProperties(){const e=super._getSerializableProperties();return{...e,layer:{...this._toPropertyDef(e.layer),default:{id:a+r(),layerType:"ArcGISFeatureLayer"}}}}_isSupportedLayer(e){return l(e)}async _applyPortalItemProperties(e){if("Feature Collection"!==e.type)throw new Error(`Cannot create Graphics Layer from Portal item that has type: ${e.type}`);const r=await e.fetchData();if(!t({layerType:"ArcGISFeatureLayer",featureCollection:r}))throw new Error("Cannot create Graphics Layer from Portal item that contains a non graphics layer feature collection");return s({layerType:"ArcGISFeatureLayer",featureCollection:r},this.layer)}_capabilities(){return this.layer?.graphics?{supportsAdd:!1,supportsDelete:!1,supportsEditing:!1,supportsQuery:!0,supportsUpdate:!1,supportsAttachmentEditing:!1,supportsStandardizedQueries:!0}:super._capabilities()}_getSerializableLayerType(){return"graphics-layer"}_getSerializableRefLayerProperties(){return this.layer.featureCollectionType?{featureCollectionType:this.layer.featureCollectionType}:{}}};y=e([i],y);export{y as GraphicsLayerExtension};