/*
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","../../../../core/Accessor","../../../../core/Handles","../../../../core/reactiveUtils","../../../../core/accessorSupport/decorators/property","../../../../core/arrayUtils","../../../../core/has","../../../../core/accessorSupport/ensureType","../../../../core/accessorSupport/decorators/subclass","../../../../geometry/projectionEllipsoid","../../support/FrustumExtentIntersection","../../../support/Scheduler"],(function(e,t,i,s,n,r,o,a,c,u,l,h,p){"use strict";const d=1.2;let g=function(t){function i(){var e;return(e=t.apply(this,arguments)||this).suspended=!1,e.extent=null,e.extentIntersectionDirty=!0,e._isVisibleBelowSurface=!1,e.handles=new s,e.graphicsCoreOwner=null,e.updating=!0,e}e._inheritsLoose(i,t);var r=i.prototype;return r.setup=function(e){this.graphicsCoreOwner=e,this.extentIntersection=new h.FrustumExtentIntersection({renderCoordsHelper:e.view.renderCoordsHelper});const t=e.view,i=t.basemapTerrain,s=t.resourceController.scheduler;this.handles.add([t.on("resize",(()=>this._viewChange())),n.watch((()=>t.state.camera),(()=>this._viewChange()),n.sync),s.registerTask(p.TaskPriority.FRUSTUM_VISIBILITY,this),i.on("elevation-bounds-change",(()=>this._elevationBoundsChange()))]),"local"===t.viewingMode?this.isVisibleBelowSurface=!0:this.handles.add([n.watch((()=>{var e,s,n;return[i.baseOpacity,i.wireframe,null==(e=t.map)||null==(s=e.ground)||null==(n=s.navigationConstraint)?void 0:n.type]}),(()=>this._updateIsVisibleBelowSurface()),n.initial)])},r.destroy=function(){this.graphicsCoreOwner=null,this.extent=null,this.extentIntersection=null,this.handles&&(this.handles.destroy(),this.handles=null)},r._setDirty=function(){this.updating||this._set("updating",!0)},r.setExtent=function(e){this.extent=e,this.extentIntersectionDirty=!0,this._setDirty()},r._viewChange=function(){this._setDirty()},r._elevationBoundsChange=function(){this._setDirty(),this.extentIntersectionDirty=!0},r._updateIsVisibleBelowSurface=function(){const e=this.graphicsCoreOwner.view,t=e.basemapTerrain,i="local"===e.viewingMode,s=e.map.ground&&e.map.ground.navigationConstraint&&"none"===e.map.ground.navigationConstraint.type;this.isVisibleBelowSurface=i||!t.opaque||s},r._updateExtentIntersection=function(){if(!this.extentIntersectionDirty)return;this.extentIntersectionDirty=!1;const e=this.graphicsCoreOwner.view;let t;if(this._isVisibleBelowSurface)t=-.3*l.getReferenceEllipsoid(e.spatialReference).radius;else{const{min:i,max:s}=e.basemapTerrain.elevationBounds;t=i-Math.max(1,(s-i)*(d-1))}this.extentIntersection.update(this.extent,e.spatialReference,t)},r.runTask=function(){if(this._set("updating",!1),!this.extent)return void this._set("suspended",!1);this._updateExtentIntersection();const e=this.graphicsCoreOwner.view.frustum,t=l.getReferenceEllipsoid(this.graphicsCoreOwner.view.spatialReference).radius;this._set("suspended",!this.extentIntersection.isVisibleInFrustum(e,t))},e._createClass(i,[{key:"isVisibleBelowSurface",set:function(e){this._isVisibleBelowSurface=e,this._setDirty(),this.extentIntersectionDirty=!0}},{key:"running",get:function(){return this.updating}}]),i}(i);t.__decorate([r.property({readOnly:!0})],g.prototype,"suspended",void 0),t.__decorate([r.property({readOnly:!0})],g.prototype,"updating",void 0),g=t.__decorate([u.subclass("esri.views.3d.layers.graphics.Graphics3DFrustumVisibility")],g);return g}));
