/* All material copyright ESRI, All Rights Reserved, unless otherwise specified. See https://js.arcgis.com/4.25/esri/copyright.txt for details. */ import{_ as e}from"../../chunks/tslib.es6.js";import t from"../../core/Error.js";import r from"../../core/Logger.js";import{isSome as i,isNone as s}from"../../core/maybe.js";import{eachAlways as o}from"../../core/promiseUtils.js";import{watch as n,syncAndInitial as a,on as l}from"../../core/reactiveUtils.js";import{property as u}from"../../core/accessorSupport/decorators/property.js";import"../../core/arrayUtils.js";import"../../core/accessorSupport/ensureType.js";import{subclass as p}from"../../core/accessorSupport/decorators/subclass.js";import{combinedViewLayerTimeExtentProperty as d}from"../../layers/support/commonProperties.js";import f from"../../layers/support/FeatureEffect.js";import c from"../../layers/support/FeatureFilter.js";import{fixFields as m,unpackFieldNames as y,collectLabelingFields as h,collectElevationFields as F,collectFilterFields as g,collectFeatureReductionFields as w,collectOrderByInfos as E,collectFields as b,collectField as x,featureHasFields as I}from"../../layers/support/fieldUtils.js";import{getFloorFilterClause as v}from"../../layers/support/floorFilterUtils.js";import R from"../../rest/support/Query.js";import{loadArcade as j}from"../../support/arcadeOnDemand.js";import{getFetchPopupTemplate as q,getRequiredFields as P}from"./support/popupUtils.js";const _="esri.views.layers.FeatureLayerView",O=r.getLogger(_),A=r=>{let A=class extends r{constructor(...e){super(...e),this._updatingRequiredFieldsPromise=null,this.filter=null,this.timeExtent=null,this.layer=null,this.requiredFields=[],this.view=null}initialize(){this.handles.add([n((()=>{const e=this.layer;return[e?.elevationInfo?.featureExpressionInfo,e&&"displayField"in e?e.displayField:null,e?.timeInfo,e&&"renderer"in e&&e.renderer,e&&"labelingInfo"in e&&e.labelingInfo,e&&"floorInfo"in e&&e.floorInfo,this.filter,this.featureEffect,this.timeExtent]}),(()=>this._handleRequiredFieldsChange()),a),l((()=>this.view?.floors),"change",(()=>this._handleRequiredFieldsChange())),l((()=>{const e=this.layer;return e&&"sublayers"in e&&e.sublayers}),"change",(()=>this._handleRequiredFieldsChange()))])}get availableFields(){const{layer:e,layer:{fieldsIndex:t},requiredFields:r}=this;return"outFields"in e&&e.outFields?m(t,[...y(t,e.outFields),...r]):m(t,r)}get featureEffect(){return this.layer&&"featureEffect"in this.layer?this.layer.featureEffect:null}set featureEffect(e){this._override("featureEffect",e)}get maximumNumberOfFeatures(){return 0}set maximumNumberOfFeatures(e){O.error("#maximumNumberOfFeatures=","Setting maximum number of features is not supported")}get maximumNumberOfFeaturesExceeded(){return!1}highlight(e){throw new Error("missing implementation")}createQuery(){const e={outFields:["*"],returnGeometry:!0,outSpatialReference:this.view.spatialReference},t=i(this.filter)?this.filter.createQuery(e):new R(e);if("feature"===this.layer.type){const e=v(this);i(e)&&(t.where=t.where?`(${t.where}) AND (${e})`:e)}return i(this.timeExtent)&&(t.timeExtent=i(t.timeExtent)?t.timeExtent.intersection(this.timeExtent):this.timeExtent.clone()),t}createAggregateQuery(){const e={outFields:["*"],returnGeometry:!0,outSpatialReference:this.view.spatialReference};return new R(e)}queryFeatures(e,t){throw new Error("missing implementation")}queryObjectIds(e,t){throw new Error("missing implementation")}queryFeatureCount(e,t){throw new Error("missing implementation")}queryExtent(e,t){throw new Error("missing implementation")}async fetchPopupFeatures(e,t){const r=this.validateFetchPopupFeatures(t);if(r)throw r;return this.fetchClientPopupFeatures(t)}_loadArcadeModules(e){if(e.get("expressionInfos.length")||Array.isArray(e.content)&&e.content.some((e=>"expression"===e.type)))return j()}_handleRequiredFieldsChange(){const e=this._updateRequiredFields();this._set("_updatingRequiredFieldsPromise",e),e.then((()=>{this._updatingRequiredFieldsPromise===e&&this._set("_updatingRequiredFieldsPromise",null)}))}async _updateRequiredFields(){if(!this.layer||!this.view)return;const e="3d"===this.view.type,{layer:t,layer:{fieldsIndex:r,objectIdField:s}}=this,n="renderer"in t&&t.renderer,a="orderBy"in t&&t.orderBy,l="featureReduction"in t?t.featureReduction:null,u=new Set,p=await o([n?n.collectRequiredFields(u,r):null,h(u,t),e?F(u,t):null,i(this.filter)?g(u,t,this.filter):null,i(this.featureEffect)?g(u,t,this.featureEffect.filter):null,l?w(u,t,l):null,a?E(u,t,a):null]);if(t.timeInfo&&this.timeExtent&&b(u,t.fieldsIndex,[t.timeInfo.startField,t.timeInfo.endField]),"feature"===t.type&&(t.floorInfo&&b(u,t.fieldsIndex,[t.floorInfo.floorField]),e&&i(t.infoFor3D)&&(null==t.globalIdField&&O.error("globalIdField missing on 3DObjectFeatureLayer"),b(u,t.fieldsIndex,[t.globalIdField]))),"subtype-group"===t.type){x(u,r,t.subtypeField);const e=t.sublayers.map((e=>Promise.all([e.renderer?.collectRequiredFields(u,r),h(u,e)])));await o(e)}for(const i of p)i.error&&O.error(i.error);x(u,r,s),e&&"displayField"in t&&t.displayField&&x(u,r,t.displayField);const d=Array.from(u).sort();this._set("requiredFields",d)}validateFetchPopupFeatures(e){if(s(e))return null;for(const r of e.clientGraphics){const i=r.layer;if("popupEnabled"in i&&!i.popupEnabled)return new t("featurelayerview:fetchPopupFeatures","Popups are disabled",{layer:i});if(r.isAggregate){const e="featureReduction"in i?i.featureReduction:null;if(!(e&&"popupTemplate"in e&&e.popupEnabled&&e.popupTemplate))return new t("featurelayerview:fetchPopupFeatures","Popups are disabled",{layer:i})}else if("popupTemplate"in i){if(!q(i,e))return new t("featurelayerview:fetchPopupFeatures","Layer does not define a popup template",{layer:i})}}}async fetchClientPopupFeatures(e){const t=i(e)?e.clientGraphics:null;if(!t||0===t.length)return[];const r=new Array(t.length),o=new Map,n=await this.createPopupQuery(e);for(let i=0;ie.layer)):[this.layer];for(const i of n){if(!("popupEnabled"in i))continue;const t=q(i,e);if(s(t))continue;const n=await this._loadArcadeModules(t),a=n&&n.arcadeUtils.hasGeometryOperations(t);o=!("point"!==this.layer.geometryType&&!a);const l=await P(this.layer,t);for(const e of l)r.add(e)}if(t.returnGeometry=o,t.returnZ=o,t.returnM=o,t.outFields=Array.from(r),t.outSpatialReference=this.view.spatialReference,"feature"===this.layer.type){const e=v(this);i(e)&&(t.where=t.where?`(${t.where}) AND (${e})`:e)}return t}canResume(){return!!super.canResume()&&(!i(this.timeExtent)||!this.timeExtent.isEmpty)}};return e([u()],A.prototype,"_updatingRequiredFieldsPromise",void 0),e([u({readOnly:!0})],A.prototype,"availableFields",null),e([u({type:f})],A.prototype,"featureEffect",null),e([u({type:c})],A.prototype,"filter",void 0),e([u(d)],A.prototype,"timeExtent",void 0),e([u()],A.prototype,"layer",void 0),e([u({type:Number})],A.prototype,"maximumNumberOfFeatures",null),e([u({readOnly:!0,type:Boolean})],A.prototype,"maximumNumberOfFeaturesExceeded",null),e([u({readOnly:!0})],A.prototype,"requiredFields",void 0),e([u()],A.prototype,"suspended",void 0),e([u()],A.prototype,"view",void 0),A=e([p(_)],A),A};export{A as default};