/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.24/esri/copyright.txt for details.
*/
define(["exports","../../../../chunks/_rollupPluginBabelHelpers","../../../../chunks/tslib.es6","../../../../core/Logger","../../../../core/accessorSupport/decorators/property","../../../../core/arrayUtils","../../../../core/has","../../../../core/accessorSupport/ensureType","../../../../core/accessorSupport/decorators/subclass","../../../../core/sql/WhereClause","../i3s/I3SUtil"],(function(e,r,i,s,n,o,t,a,p,l,d){"use strict";const u=s.getLogger("esri.views.3d.layers.support.DefinitionExpressionSceneLayerView"),c=e=>{let s=function(e){function i(){var r;return(r=e.apply(this,arguments)||this)._definitionExpressionErrors=0,r._maxDefinitionExpressionErrors=20,r.logError=e=>{r._definitionExpressionErrors<r._maxDefinitionExpressionErrors&&u.error("Error while evaluating definitionExpression: "+e),r._definitionExpressionErrors++,r._definitionExpressionErrors===r._maxDefinitionExpressionErrors&&u.error("Further errors are ignored")},r}r._inheritsLoose(i,e);var s=i.prototype;return s._evaluateClause=function(e,r){try{return e.testFeature(r)}catch(i){return this.logError(i),!1}},s._addDefinitionExpressionToQuery=function(e){if(!this.parsedDefinitionExpression)return e;const r=this.i3slayer.definitionExpression,i=e.clone();return i.where?i.where=`(${r}) AND (${i.where})`:i.where=r,i},r._createClass(i,[{key:"parsedDefinitionExpression",get:function(){if(!this.i3slayer||!this.i3slayer.definitionExpression)return null;try{const e=l.WhereClause.create(this.i3slayer.definitionExpression,this.i3slayer.fieldsIndex);if(!e.isStandardized)return u.error("definitionExpression is using non standard function"),null;const r=[],i=e.fieldNames;return d.findFieldsCaseInsensitive(i,this.i3slayer.fields,{missingFields:r}),r.length>0?(u.error(`definitionExpression references unknown fields: ${r.join(", ")}`),null):(this._definitionExpressionErrors=0,e)}catch(e){return u.error("Failed to parse definitionExpression: "+e),null}}},{key:"definitionExpressionFields",get:function(){return this.parsedDefinitionExpression?this.parsedDefinitionExpression.fieldNames:null}}]),i}(e);return i.__decorate([n.property()],s.prototype,"i3slayer",void 0),i.__decorate([n.property({readOnly:!0})],s.prototype,"parsedDefinitionExpression",null),i.__decorate([n.property({readOnly:!0})],s.prototype,"definitionExpressionFields",null),s=i.__decorate([p.subclass("esri.views.3d.layers.support.DefinitionExpressionSceneLayerView")],s),s};e.DefinitionExpressionSceneLayerView=c,Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
