/* COPYRIGHT Esri - https://js.arcgis.com/5.0/LICENSE.txt */
import{__decorate as r}from"tslib";import i from"../../../../core/Logger.js";import{property as e,subclass as s}from"../../../../core/accessorSupport/decorators.js";import n from"../../../../core/sql/WhereClause.js";import{findFieldsCaseInsensitive as o}from"../i3s/I3SUtil.js";const t=t=>{const l=t;let d=class extends l{constructor(){super(...arguments),this._definitionExpressionErrors=0,this._maxDefinitionExpressionErrors=20,this.logError=r=>{this._definitionExpressionErrors<this._maxDefinitionExpressionErrors&&i.getLogger(this).error("Error while evaluating definitionExpression: "+r),this._definitionExpressionErrors++,this._definitionExpressionErrors===this._maxDefinitionExpressionErrors&&i.getLogger(this).error("Further errors are ignored")}}get parsedDefinitionExpression(){if(!this.i3slayer?.definitionExpression)return null;try{const r=n.create(this.i3slayer.definitionExpression,{fieldsIndex:this.i3slayer.fieldsIndex});if(!r.isStandardized)return i.getLogger(this).error("definitionExpression is using non standard function"),null;const e=[],s=r.fieldNames;return o(s,this.i3slayer.fieldsIndex,{missingFields:e}),e.length>0?(i.getLogger(this).error(`definitionExpression references unknown fields: ${e.join(", ")}`),null):(this._definitionExpressionErrors=0,r)}catch(r){return i.getLogger(this).error("Failed to parse definitionExpression: "+r),null}}get definitionExpressionFields(){return this.parsedDefinitionExpression?this.parsedDefinitionExpression.fieldNames:[]}_evaluateClause(r,i){if(null==r)return!0;try{return r.testFeature(i)}catch(e){return this.logError(e),!1}}_addDefinitionExpressionToQuery(r){if(!this.parsedDefinitionExpression)return r;const i=this.i3slayer.definitionExpression,e=r.clone();return e.where?e.where=`(${i}) AND (${e.where})`:e.where=i,e}};return r([e({readOnly:!0})],d.prototype,"parsedDefinitionExpression",null),r([e({readOnly:!0})],d.prototype,"definitionExpressionFields",null),d=r([s("esri.views.3d.layers.support.DefinitionExpressionSceneLayerView")],d),d};export{t as DefinitionExpressionSceneLayerView};
