/*
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/asyncUtils","../../../../core/maybe","../../../../core/promiseUtils","./Graphics3DGraphic","./Graphics3DObject3DGraphicLayer","./Graphics3DSymbolLayerFactory","./interfaces","./Loadable","./symbolComplexity"],(function(e,t,s,r,o,n,a,i,l,y){"use strict";let c=function(c){function u(e,t,s){var r;return(r=c.call(this,t.schedule)||this)._symbol=e,r._context=t,r._backgroundLayers=s,r._destroyed=!1,r.symbolLayers=new Array,r.referenced=0,r._extentPadding=0,r}e._inheritsLoose(u,c);var d=u.prototype;return d.doLoad=function(){var o=e._asyncToGenerator((function*(o){var n=this;let i=this._symbol.symbolLayers;this._extentPadding=0,this._backgroundLayers&&(i=this._backgroundLayers.concat(i));const l=i.length;for(;this.symbolLayers.length<i.length;)this.symbolLayers.push(null);this.symbolLayers.length=i.length;const y=[];for(let e=0;e<l;e++){const t=i.getItemAt(e);if(!1===t.enabled)continue;h.renderPriority=1-(1+e)/l,h.renderPriorityStep=1/l,h.ignoreDrivers=t._ignoreDrivers;const s=a.make(this.symbol,t,this._context,h);y.push(r.onAbortOrThrow(o,(()=>{this.symbolLayers[e]=null,s.destroy()}))),this.symbolLayers[e]=s}yield t.forEach(this.symbolLayers,function(){var t=e._asyncToGenerator((function*(e,t){if(s.isSome(e))try{yield e.load(),n._extentPadding+=Math.max(n._extentPadding,e.extentPadding)}catch{n.symbolLayers[t]=null}}));return function(e,s){return t.apply(this,arguments)}}());for(const e of y)null==e||e.remove();if(y.length=0,r.throwIfAborted(o),this.symbolLayers.length&&!this.symbolLayers.some((e=>!!e)))throw new Error}));function n(e){return o.apply(this,arguments)}return n}(),d.getSymbolLayerSize=function(e){const t=this.symbolLayers[e];return s.isSome(t)?t.getCachedSize():null},d.createGraphics3DGraphic=function(e,t){const r=e.graphic,n=new Array(this.symbolLayers.length);for(let o=0;o<this.symbolLayers.length;o++){const t=this.symbolLayers[o];n[o]=s.isSome(t)?t.createGraphics3DGraphic(e):null}const a=this._context.arcade||this._context.featureExpressionInfoContext&&this._context.featureExpressionInfoContext.arcade&&this._context.featureExpressionInfoContext.arcade.modules||null;return new o(r,t||this,n,e.layer,a)},d.globalPropertyChanged=function(e,t){const r=this.symbolLayers.length;for(let o=0;o<r;o++){const r=this.symbolLayers[o],a=e=>{const t=e.graphics[o];return t instanceof n.Graphics3DObject3DGraphicLayer?t:null};if(s.isSome(r)&&!r.globalPropertyChanged(e,t,a))return!1}return!0},d.applyRendererDiff=function(e,t){return this.loadStatus!==l.LoadStatus.LOADED?i.ApplyRendererDiffResult.Recreate_Symbol:this.symbolLayers.reduce(((r,o)=>r!==i.ApplyRendererDiffResult.Recreate_Symbol&&s.isSome(o)?Math.min(r,o.applyRendererDiff(e,t)):r),i.ApplyRendererDiffResult.Fast_Update)},d.prepareSymbolPatch=function(e){if(this.loadStatus===l.LoadStatus.FAILED)return;if("partial"!==e.diff.type)return;const t=e.diff.diff;if(!t.symbolLayers||"partial"!==t.symbolLayers.type)return;const r=t.symbolLayers.diff;this.symbolLayers.forEach(((t,o)=>{if(s.isNone(t))return;const n=r[o];if(n){const r={diff:n,graphics3DGraphicPatches:[],symbolLayerStatePatches:[]};t.prepareSymbolLayerPatch(r),e.symbolStatePatches.push(...r.symbolLayerStatePatches),r.graphics3DGraphicPatches.length&&e.graphics3DGraphicPatches.push(((e,t)=>{const n=e.graphics[o];s.isSome(n)&&r.graphics3DGraphicPatches.forEach((e=>e(n,t)))}))}}))},d.updateGeometry=function(e,t){for(let r=0;r<this.symbolLayers.length;r++){const o=this.symbolLayers[r];if(s.isNone(o))continue;const n=e.graphics[r];if(s.isNone(n)||!o.updateGeometry(n,t))return!1}return!0},d.onRemoveGraphic=function(e){for(let t=0;t<this.symbolLayers.length;t++){const r=this.symbolLayers[t];if(s.isNone(r))continue;const o=e.graphics[t];s.isSome(o)&&r.onRemoveGraphic(o)}},d.getFastUpdateStatus=function(){let e=0,t=0,r=0;return this.symbolLayers.forEach((o=>{s.isNone(o)||(o.loadStatus===l.LoadStatus.LOADING?e++:o.isFastUpdatesEnabled()?r++:t++)})),{loading:e,slow:t,fast:r}},d.destroy=function(){if(this.destroyed)console.error("Graphics3DSymbol.destroy called when already destroyed!");else{c.prototype.destroy.call(this);for(const e of this.symbolLayers)s.isSome(e)&&e.destroy();this.symbolLayers.length=0,this._destroyed=!0}},e._createClass(u,[{key:"symbol",get:function(){return this._symbol},set:function(e){this._symbol=e;for(let t=0;t<e.symbolLayers.length;t++){const r=this.symbolLayers[t];s.isNone(r)||(r.symbol=e,r.symbolLayer=e.symbolLayers.items[t])}}},{key:"extentPadding",get:function(){return this._extentPadding}},{key:"complexity",get:function(){return y.totalSymbolComplexities(this.symbolLayers.map((e=>s.get(e,"complexity"))))}},{key:"destroyed",get:function(){return this._destroyed}}]),u}(l.Loadable);const h={renderPriority:0,renderPriorityStep:1,ignoreDrivers:!1};return c}));
