/*
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","../../../../../core/maybe","../../../../../core/typedArrayUtil","./IndexRange/ComponentRangeRunLengthEncoded","../../lib/AutoDisposable"],(function(e,t,i,n,h){"use strict";function s(e,t,i){const n=[],h=[];let s=i.length,a=i.length;return t.forEachComponent((t=>(e[t]>0?(s!==t-1&&(n.length&&n.push(i[s+1]-n[n.length-1]),n.push(i[t])),s=t):(a!==t-1&&(h.length&&h.push(i[a+1]-h[h.length-1]),h.push(i[t])),a=t),!0))),n.length&&n.push(i[s+1]-n[n.length-1]),h.length&&h.push(i[a+1]-h[h.length-1]),{highlightRanges:n,defaultRanges:h}}return function(h){function a(e,t){var s;(s=h.call(this)||this).pickability=null,s.highlightCounts=null,s.verticalOffsets=null,s.cachedGeometryRanges=null,s.cachedHighlightRanges=null,s.cachedDefaultRanges=null,s.offsets=i.slice(t);const a=s.count;s.visibility=new n.ComponentRangeRunLengthEncoded(a),s.materialDataBuffer=e.getBuffer(a),s.materialDataIndices=new Uint16Array(a);for(let i=0;i<a;i++)s.materialDataIndices[i]=s.materialDataBuffer.acquireIndex();return s}e._inheritsLoose(a,h);var l=a.prototype;return l.dispose=function(){h.prototype.dispose.call(this);for(let e=0;e<this.count;e++)this.materialDataBuffer.releaseIndex(this.materialDataIndices[e])},l.highlightsDirty=function(){this.cachedHighlightRanges=null,this.cachedDefaultRanges=null},l.visibilityDirty=function(){this.cachedGeometryRanges=null,this.highlightsDirty()},l._updateCachedHighlightRanges=function(){if((t.isNone(this.cachedHighlightRanges)||t.isNone(this.cachedDefaultRanges))&&t.isSome(this.highlightCounts)){const{highlightRanges:e,defaultRanges:t}=s(this.highlightCounts,this.visibility,this.offsets);this.cachedHighlightRanges=e,this.cachedDefaultRanges=t}},e._createClass(a,[{key:"count",get:function(){return this.offsets.length-1}},{key:"geometryRanges",get:function(){return t.isNone(this.cachedGeometryRanges)&&(this.cachedGeometryRanges=this.visibility.computeOffsetRanges(this.offsets)),this.cachedGeometryRanges}},{key:"highlightRanges",get:function(){return t.isNone(this.highlightCounts)?null:(this._updateCachedHighlightRanges(),this.cachedHighlightRanges)}},{key:"defaultShadowMapRanges",get:function(){return t.isNone(this.highlightCounts)?this.geometryRanges:(this._updateCachedHighlightRanges(),this.cachedDefaultRanges)}}]),a}(h.AutoDisposable)}));
