/* All material copyright ESRI, All Rights Reserved, unless otherwise specified. See https://js.arcgis.com/4.24/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/has.js";import"../core/accessorSupport/set.js";import{subclass as i}from"../core/accessorSupport/decorators/subclass.js";const p=p=>{let a=class extends p{async fetchPopupFeatures(e,r){await this.when();const{location:i,queryArea:p,layerViewsAndGraphics:a,clientOnlyGraphics:t}=await this._prepareFetchPopupFeatures(e,r),o=Promise.resolve(t),c=this._queryLayerPopupFeatures(p,a,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:p})=>{const a={clientGraphics:p,event:r(i)?i.event:null,signal:r(i)?i.signal:null,defaultPopupTemplateEnabled:!!r(i)&&!!i.defaultPopupTemplateEnabled},t=s.fetchPopupFeatures(e,a);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:p}=await this._popupHitTestGraphics(e,r),a=this._getFetchPopupLayerViews(),{layerViewsAndGraphics:t,clientOnlyGraphics:o}=this._graphicsPerFetchPopupLayerView(s,a);return{clientOnlyGraphics:o,layerViewsAndGraphics:t,queryArea:i,location:p}}async _popupHitTestGraphics(e,r){const{results:s,mapPoint:i}=await this.popupHitTest(e),p=s.filter((e=>"graphic"===e.type&&this._isValidPopupGraphic(e.graphic,r))),a=p.length?p[0].mapPoint:null;return{clientGraphics:p.map((e=>e.graphic)),queryArea:i,location:i||a}}_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,p=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 a of e){const e=i.get(a.layer)||i.get(a.sourceLayer)||null;e?e.push(a):s.push(a)}return{layerViewsAndGraphics:p,clientOnlyGraphics:s}}};return a=e([i("esri.views.PopupView")],a),a};export{p as PopupView};