/*
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/has","../../../../core/maybe","../../../../chunks/mat3f32","../brushes","../Container","./ClippingInfo","./enums"],(function(e,r,t,n,s,i,a,o){"use strict";let c=function(r){function i(){var e;return(e=r.apply(this,arguments)||this).name=e.constructor.name,e}e._inheritsLoose(i,r);var c=i.prototype;return c._createTransforms=function(){return{dvs:n.create()}},c.doRender=function(e){const r=this.createRenderParams(e),{painter:t,globalOpacity:n,profiler:s,drawPhase:i}=r,a=i===o.WGLDrawPhase.LABEL||i===o.WGLDrawPhase.HIGHLIGHT?1:n*this.computedOpacity;s.recordContainerStart(this.name),t.beforeRenderLayer(r,this._clippingInfos?255:0,a),this.updateTransforms(e.state),this.renderChildren(r),t.compositeLayer(r,a),s.recordContainerEnd()},c.renderChildren=function(e){t.isNone(this._renderPasses)&&(this._renderPasses=this.prepareRenderPasses(e.painter));for(const t of this.children)t.beforeRender(e);for(const t of this._renderPasses)try{t.render(e)}catch(r){}for(const t of this.children)t.afterRender(e)},c.createRenderParams=function(e){return e.requireFBO=this.requiresDedicatedFBO,e},c.prepareRenderPasses=function(e){return[e.registerRenderPass({name:"clip",brushes:[s.brushes.clip],target:()=>this._clippingInfos,drawPhase:o.WGLDrawPhase.MAP|o.WGLDrawPhase.LABEL|o.WGLDrawPhase.LABEL_ALPHA|o.WGLDrawPhase.DEBUG|o.WGLDrawPhase.HIGHLIGHT})]},c.updateTransforms=function(e){for(const r of this.children)r.setTransform(e)},c.onAttach=function(){r.prototype.onAttach.call(this),this._updateClippingInfo()},c.onDetach=function(){r.prototype.onDetach.call(this),this._updateClippingInfo()},c._updateClippingInfo=function(){if(t.isSome(this._clippingInfos)&&(this._clippingInfos.forEach((e=>e.destroy())),this._clippingInfos=null),!this.stage)return;const e=this._clips;t.isSome(e)&&e.length&&(this._clippingInfos=e.items.map((e=>a.fromClipArea(this.stage,e)))),this.requestRender()},e._createClass(i,[{key:"clips",set:function(e){this._clips=e,this.children.forEach((r=>r.clips=e)),this._updateClippingInfo()}}]),i}(i.Container);return c}));
