/* 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{isSome as r}from"../core/maybe.js";import{eachAlwaysValues as s}from"../core/promiseUtils.js";import"../core/Logger.js";import"../core/accessorSupport/ensureType.js";import"../core/arrayUtils.js";import"../core/Error.js";import"../core/has.js";import{subclass as i}from"../core/accessorSupport/decorators/subclass.js";const a=a=>{let p=class extends a{async fetchPopupFeatures(e,r){await this.when();const{location:i,queryArea:a,layerViewsAndGraphics:p,clientOnlyGraphics:t}=await this._prepareFetchPopupFeatures(e,r),o=Promise.resolve(t),c=this._queryLayerPopupFeatures(a,p,r),n=c.map((e=>e.promise));return{location:i,clientOnlyGraphics:t,allGraphicsPromise:s([o,...n]).then((e=>Array.from(new Set(e.flat())))),promisesPerLayerView:c}}_queryLayerPopupFeatures(e,s,i){return s.map((({layerView:s,graphics:a})=>{const p={clientGraphics:a,event:r(i)?i.event:null,signal:r(i)?i.signal:null,defaultPopupTemplateEnabled:!!r(i)&&!!i.defaultPopupTemplateEnabled},t=s.fetchPopupFeatures(e,p);return{layerView:s,promise:t}}))}_isValidPopupGraphic(e,s){return e&&!!e.getEffectivePopupTemplate(r(s)&&s.defaultPopupTemplateEnabled)}async _prepareFetchPopupFeatures(e,r){const{clientGraphics:s,queryArea:i,location:a}=await this._popupHitTestGraphics(e,r),p=this._getFetchPopupLayerViews(),{layerViewsAndGraphics:t,clientOnlyGraphics:o}=this._graphicsPerFetchPopupLayerView(s,p);return{clientOnlyGraphics:o,layerViewsAndGraphics:t,queryArea:i,location:a}}async _popupHitTestGraphics(e,r){const{results:s,mapPoint:i}=await this.popupHitTest(e),a=s.filter((e=>"graphic"===e.type&&this._isValidPopupGraphic(e.graphic,r))),p=a.length?a[0].mapPoint:null;return{clientGraphics:a.map((e=>e.graphic)),queryArea:i,location:i||p}}_getFetchPopupLayerViews(){const e=[];return this.allLayerViews.forEach((r=>{this._isValidPopupLayerView(r)&&e.push(r)})),r(this.graphicsView)&&this._isValidPopupLayerView(this.graphicsView)&&e.push(this.graphicsView),e.reverse()}_isValidPopupLayerView(e){return r(e)&&(!("layer"in e)||!e.suspended)&&"fetchPopupFeatures"in e}_graphicsPerFetchPopupLayerView(e,r){const s=[],i=new Map,a=r.map((e=>{const r=[];return"layer"in e?i.set(e.layer,r):i.set(e.graphics,r),{layerView:e,graphics:r}}));for(const p of e){const e=i.get(p.layer)||i.get(p.sourceLayer)||null;e?e.push(p):s.push(p)}return{layerViewsAndGraphics:a,clientOnlyGraphics:s}}};return p=e([i("esri.views.PopupView")],p),p};export{a as PopupView};