/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.24/esri/copyright.txt for details.
*/
define(["../../../chunks/_rollupPluginBabelHelpers","../../../chunks/tslib.es6","../../../Graphic","../../../core/Collection","../../../core/maybe","../../../core/reactiveUtils","../../../core/Logger","../../../core/accessorSupport/ensureType","../../../core/arrayUtils","../../../core/has","../../../core/accessorSupport/set","../../../core/accessorSupport/decorators/subclass","./LayerView2D","./graphics/GraphicContainer","./graphics/GraphicsView2D","../../layers/LayerView"],(function(i,e,t,s,r,a,h,n,o,c,l,p,u,g,d,f){"use strict";const w="sublayers",y="layerView",_=Object.freeze({remove(){},pause(){},resume(){}});let m=function(e){function h(){var i;return(i=e.apply(this,arguments)||this)._highlightIds=new Map,i}i._inheritsLoose(h,e);var n=h.prototype;return n.fetchPopupFeatures=function(){var e=i._asyncToGenerator((function*(i){return Array.from(this.graphicsViews(),(e=>e.hitTest(i).filter((i=>!!i.popupTemplate)))).flat()}));function t(i){return e.apply(this,arguments)}return t}(),n.graphicsViews=function*(){r.isSome(this._graphicsViewsFeatureCollectionMap)?yield*this._graphicsViewsFeatureCollectionMap.keys():r.isSome(this._graphicsViews)?yield*this._graphicsViews:yield*[]},n.hitTest=function(){var e=i._asyncToGenerator((function*(i,e){return Array.from(this.graphicsViews(),(e=>{const t=e.hitTest(i);if(r.isSome(this._graphicsViewsFeatureCollectionMap)){const i=this._graphicsViewsFeatureCollectionMap.get(e);for(const e of t)!e.popupTemplate&&i.popupTemplate&&(e.popupTemplate=i.popupTemplate)}return t})).flat().map((e=>({type:"graphic",graphic:e,layer:this.layer,mapPoint:i})))}));function t(i,t){return e.apply(this,arguments)}return t}(),n.highlight=function(i){let e;return"number"==typeof i?e=[i]:i instanceof t?e=[i.uid]:Array.isArray(i)&&i.length>0?e="number"==typeof i[0]?i:i.map((i=>i&&i.uid)):s.isCollection(i)&&(e=i.map((i=>i&&i.uid)).toArray()),e=e.filter((i=>null!=i)),e.length?(this._addHighlight(e),{remove:()=>{this._removeHighlight(e)}}):_},n.update=function(i){for(const e of this.graphicsViews())e.processUpdate(i)},n.attach=function(){const i=this.view,e=()=>this.requestUpdate(),t=this.layer.featureCollections;if(r.isSome(t)&&t.length){this._graphicsViewsFeatureCollectionMap=new Map;for(const s of t){const t=new g(this.view.featuresTilingScheme);t.fadeTransitionEnabled=!0;const r=new d({view:i,graphics:s.source,renderer:s.renderer,requestUpdateCallback:e,container:t});this._graphicsViewsFeatureCollectionMap.set(r,s),this.container.addChild(r.container),this.handles.add([a.watch((()=>s.visible),(i=>r.container.visible=i),a.initial),a.watch((()=>r.updating),(()=>this.notifyChange("updating")),a.initial)],y)}this._updateHighlight()}else r.isSome(this.layer.sublayers)&&this.handles.add(a.on((()=>this.layer.sublayers),"change",(()=>this._createGraphicsViews()),{onListenerAdd:()=>this._createGraphicsViews(),onListenerRemove:()=>this._destroyGraphicsViews()}),w)},n.detach=function(){this._destroyGraphicsViews(),this.handles.remove(w)},n.moveStart=function(){},n.moveEnd=function(){},n.viewChange=function(){for(const i of this.graphicsViews())i.viewChange()},n.isUpdating=function(){for(const i of this.graphicsViews())if(i.updating)return!0;return!1},n._destroyGraphicsViews=function(){this.container.removeAllChildren(),this.handles.remove(y);for(const i of this.graphicsViews())i.destroy();this._graphicsViews=null,this._graphicsViewsFeatureCollectionMap=null},n._createGraphicsViews=function(){if(this._destroyGraphicsViews(),r.isNone(this.layer.sublayers))return;const i=[],e=this.view,t=()=>this.requestUpdate();for(const s of this.layer.sublayers){const r=new g(this.view.featuresTilingScheme);r.fadeTransitionEnabled=!0;const h=new d({view:e,graphics:s.graphics,requestUpdateCallback:t,container:r});this.handles.add([s.on("graphic-update",h.graphicUpdateHandler),a.watch((()=>s.visible),(i=>h.container.visible=i),a.initial),a.watch((()=>h.updating),(()=>this.notifyChange("updating")),a.initial)],y),this.container.addChild(h.container),i.push(h)}this._graphicsViews=i,this._updateHighlight()},n._addHighlight=function(i){for(const e of i)if(this._highlightIds.has(e)){const i=this._highlightIds.get(e);this._highlightIds.set(e,i+1)}else this._highlightIds.set(e,1);this._updateHighlight()},n._removeHighlight=function(i){for(const e of i)if(this._highlightIds.has(e)){const i=this._highlightIds.get(e)-1;0===i?this._highlightIds.delete(e):this._highlightIds.set(e,i)}this._updateHighlight()},n._updateHighlight=function(){const i=Array.from(this._highlightIds.keys());for(const e of this.graphicsViews())e.setHighlight(i)},h}(u.LayerView2DMixin(f));m=e.__decorate([p.subclass("esri.views.2d.layers.MapNotesLayerView2D")],m);return m}));
