/*
All material copyright Esri, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/5.0/esri/copyright.txt for details.
*/
import{__decorate as e}from"tslib";import r from"../../core/Collection.js";import{handlesGroup as t,makeHandle as i}from"../../core/handleUtils.js";import s from"../../core/Logger.js";import{debounce as a,ignoreAbortErrors as o}from"../../core/promiseUtils.js";import{sqlAnd as n}from"../../core/sql.js";import{property as d,subclass as p}from"../../core/accessorSupport/decorators.js";import l from"./LayerView.js";const y=Symbol(),u=l=>{const u=l;let m=class extends u{constructor(...e){super(...e),this.layerViews=new r,this._debouncedUpdate=a(async()=>{const{layer:e,parent:r}=this,t=r?.footprintLayerView;let i=[];const s=this._createQuery();if(s&&t){const{features:r}=await t.queryFeatures(s);this.suspended||(i=r.map(r=>e.acquireLayer(r)))}this.removeHandles(y),this.addHandles(i,y)})}get creatingLayerViews(){return this.view?.layerViewManager.isCreatingLayerViewsForLayer(this.layer)??!1}isUpdating(){return this.creatingLayerViews||this.layer.updating||this.layerViews.some(e=>e.updating)}enableLayerUpdates(){return t([this._updatingHandles.addWhen(()=>!1===this.parent?.footprintLayerView?.dataUpdating,()=>this.updateLayers()),this._updatingHandles.add(()=>[this.layer.maximumVisibleSublayers,this.layer.parent?.orderBy,this.parent?.footprintLayerView?.filter,this.parent?.footprintLayerView?.timeExtent,this.suspended],()=>this.updateLayers()),i(()=>this.removeHandles(y))])}updateLayers(){this.suspended?this.removeHandles(y):this._updatingHandles.addPromise(o(this._debouncedUpdate()).catch(e=>{s.getLogger(this).error(e)}))}_createQuery(){const e=this.parent?.footprintLayerView,r=this.layer?.parent;if(!e||!r||r.destroyed)return null;const{layer:{maximumVisibleSublayers:t},view:{scale:i}}=this;if(!t)return null;const{itemTypeField:s,itemSourceField:a,itemNameField:o,minScaleField:d,maxScaleField:p,objectIdField:l,orderBy:y}=r,u=n(`${d} IS NULL OR ${i} <= ${d} OR ${d} = 0`,`${p} IS NULL OR ${i} >= ${p}`),m=y?.find(e=>e.field&&!e.valueExpression),c=e.createQuery();if(c.returnGeometry=!1,c.num=t,c.outFields=[l,a,o],c.where=n(c.where,u),null!=this.unsupportedItemTypes){const e=`${s} NOT IN (${this.unsupportedItemTypes.map(e=>`'${e}'`)})`;c.where=n(c.where,e)}return m?.field&&(c.orderByFields=[`${m.field} ${"descending"===m.order?"DESC":"ASC"}`],c.outFields.push(m.field)),c}};return e([d({readOnly:!0})],m.prototype,"creatingLayerViews",null),e([d()],m.prototype,"layer",void 0),e([d()],m.prototype,"layerViews",void 0),e([d({readOnly:!0})],m.prototype,"unsupportedItemTypes",void 0),e([d()],m.prototype,"parent",void 0),e([d({readOnly:!0})],m.prototype,"isUpdating",null),m=e([p("esri.views.layers.CatalogDynamicGroupLayerView")],m),m},m=u(l);export{m as CatalogDynamicGroupLayerView,u as CatalogDynamicGroupLayerViewMixin};
