import{__decorate as e}from"tslib";import{_isRouteLayerJson as r}from"../json/FeatureLayerJson.js";import{applyJsonToLayer as t}from"../json/LayerJson.js";import{serializable as a}from"../support/Serializable.js";import{watch as s}from"../support/observableUtils.js";import{isRouteLayer as o}from"../utilities/_layers.js";import{checkArg as i}from"../utilities/checkArg.js";import{LayerExtension as l,LayerExtensionSchema as p}from"./_LayerExtension.js";export const ROUTE_LAYER_TYPE="route-layer";let n=class extends l{get hasFeatures(){return!0}get layer(){return super.layer}get supportsSublayers(){return!1}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 s(this,"layer",(e=>{e._fields&&this.schema?.fields&&(this.schema.fields.removeAll(),this.schema.fields.addMany(e._fields))})),super._onInitialize()}_applyLayerProperties(e,t){return e.hasOwnProperty("featureCollection")&&i("layerJson",e).satisfies(r),super._applyLayerProperties(e,t)}_getSerializableProperties(){const e=super._getSerializableProperties();return{...e,layer:{...this._toPropertyDef(e.layer),default:{layerType:"ArcGISFeatureLayer",featureCollectionType:"route"}}}}_isSupportedLayer(e){return o(e)}async _applyPortalItemProperties(e){if("Feature Collection"!==e.type)throw new Error(`Cannot create Route Layer from Portal item that has type: ${e.type}`);const a=await e.fetchData();if(!r({layerType:"ArcGISFeatureLayer",featureCollection:a}))throw new Error("Cannot create Route Layer from Portal item that contains a non route layer feature collection");return t({layerType:"ArcGISFeatureLayer",featureCollection:a},this.layer)}_capabilities(){return{supportsAdd:!1,supportsDelete:!1,supportsEditing:!1,supportsQuery:!0,supportsUpdate:!1,supportsAttachmentEditing:!1,supportsStandardizedQueries:!0}}_getSerializableLayerType(){return"route-layer"}_getSerializableRefLayerProperties(){return this.layer?.featureCollectionType?{featureCollectionType:this.layer.featureCollectionType}:{}}_createSchema(){const e=new y(this);return e.primaryKeyField="globalid",e}};n=e([a],n);export{n as RouteLayerExtension};let y=class extends p{get hasGeometry(){return!0}};y=e([a],y);export{y as RouteLayerExtensionSchema};