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