/*
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/maybe","../core/promiseUtils","../core/Logger","../core/accessorSupport/ensureType","../core/arrayUtils","../core/has","../core/accessorSupport/set","../core/accessorSupport/decorators/subclass"],(function(e,r,i,t,s,a,p,n,o,c,u){"use strict";const l=e=>{let a=function(e){function i(){return e.apply(this,arguments)||this}r._inheritsLoose(i,e);var a=i.prototype;return a.fetchPopupFeatures=function(){var e=r._asyncToGenerator((function*(e,r){yield this.when();const{location:i,queryArea:t,layerViewsAndGraphics:a,clientOnlyGraphics:p}=yield this._prepareFetchPopupFeatures(e,r),n=Promise.resolve(p),o=this._queryLayerPopupFeatures(t,a,r),c=o.map((e=>e.promise));return{location:i,clientOnlyGraphics:p,allGraphicsPromise:s.eachAlwaysValues([n,...c]).then((e=>Array.from(new Set(e.flat())))),promisesPerLayerView:o}}));function i(r,i){return e.apply(this,arguments)}return i}(),a._queryLayerPopupFeatures=function(e,r,i){return r.map((({layerView:r,graphics:s})=>{const a={clientGraphics:s,event:t.isSome(i)?i.event:null,signal:t.isSome(i)?i.signal:null,defaultPopupTemplateEnabled:!!t.isSome(i)&&!!i.defaultPopupTemplateEnabled},p=r.fetchPopupFeatures(e,a);return{layerView:r,promise:p}}))},a._isValidPopupGraphic=function(e,r){return e&&!!e.getEffectivePopupTemplate(t.isSome(r)&&r.defaultPopupTemplateEnabled)},a._prepareFetchPopupFeatures=function(){var e=r._asyncToGenerator((function*(e,r){const{clientGraphics:i,queryArea:t,location:s}=yield this._popupHitTestGraphics(e,r),a=this._getFetchPopupLayerViews(),{layerViewsAndGraphics:p,clientOnlyGraphics:n}=this._graphicsPerFetchPopupLayerView(i,a);return{clientOnlyGraphics:n,layerViewsAndGraphics:p,queryArea:t,location:s}}));function i(r,i){return e.apply(this,arguments)}return i}(),a._popupHitTestGraphics=function(){var e=r._asyncToGenerator((function*(e,r){const{results:i,mapPoint:t}=yield this.popupHitTest(e),s=i.filter((e=>"graphic"===e.type&&this._isValidPopupGraphic(e.graphic,r))),a=s.length?s[0].mapPoint:null;return{clientGraphics:s.map((e=>e.graphic)),queryArea:t,location:t||a}}));function i(r,i){return e.apply(this,arguments)}return i}(),a._getFetchPopupLayerViews=function(){const e=[];return this.allLayerViews.forEach((r=>{this._isValidPopupLayerView(r)&&e.push(r)})),t.isSome(this.graphicsView)&&this._isValidPopupLayerView(this.graphicsView)&&e.push(this.graphicsView),e.reverse()},a._isValidPopupLayerView=function(e){return t.isSome(e)&&(!("layer"in e)||!e.suspended)&&"fetchPopupFeatures"in e},a._graphicsPerFetchPopupLayerView=function(e,r){const i=[],t=new Map,s=r.map((e=>{const r=[];return"layer"in e?t.set(e.layer,r):t.set(e.graphics,r),{layerView:e,graphics:r}}));for(const a of e){const e=t.get(a.layer)||t.get(a.sourceLayer)||null;e?e.push(a):i.push(a)}return{layerViewsAndGraphics:s,clientOnlyGraphics:i}},i}(e);return a=i.__decorate([u.subclass("esri.views.PopupView")],a),a};e.PopupView=l,Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
