/*
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","../../../../geometry","../../../../core/Accessor","../../../../core/Logger","../../../../core/mathUtils","../../../../core/maybe","../../../../core/promiseUtils","../../../../core/accessorSupport/decorators/property","../../../../core/arrayUtils","../../../../core/has","../../../../core/accessorSupport/ensureType","../../../../core/accessorSupport/decorators/subclass","../../../../geometry/Point","./FlowDisplayData","./FlowDisplayObject","../../../../geometry/Extent"],(function(e,t,o,i,a,r,n,s,l,c,d,p,u,y,h,_,f){"use strict";const g=1.15,m=a.getLogger("esri.views.2d.engine.flow.FlowStrategy");let w=function(t){function o(e){var o;return(o=t.call(this,e)||this)._flowDisplayObject=new _.FlowDisplayObject,o._loading=null,o}e._inheritsLoose(o,t);var i=o.prototype;return i.initialize=function(){this.flowContainer.addChild(this._flowDisplayObject)},i.destroy=function(){this._clear(),this.flowContainer.removeAllChildren()},i.update=function(e){const{flowStyle:t}=this.flowContainer;if(n.isNone(t))return void this._clear();const{extent:o,rotation:i,resolution:a,pixelRatio:r}=e.state,l=x(o,i);l.expand(g);const c=[Math.round((l.xmax-l.xmin)/a),Math.round((l.ymax-l.ymin)/a)],d=new h(t,l,c,r);if(n.isSome(this._loading)){if(this._loading.update(d))return;this._loading.detach(),this._loading=null}!n.isNone(this._flowDisplayObject.displayData)&&this._flowDisplayObject.displayData.update(d)||(d.load().then((()=>{this._flowDisplayObject.clear(),this._flowDisplayObject.displayData=this._loading,this._loading=null}),(e=>{s.isAbortError(e)||(m.error("A resource failed to load.",e),this._loading=null)})),this._loading=d)},i._clear=function(){this._flowDisplayObject.clear(),n.isSome(this._loading)&&(this._loading.detach(),this._loading=null)},e._createClass(o,[{key:"updating",get:function(){return null!=this._loading}}]),o}(i);t.__decorate([l.property()],w.prototype,"_loading",void 0),t.__decorate([l.property()],w.prototype,"flowContainer",void 0),t.__decorate([l.property()],w.prototype,"updating",null),w=t.__decorate([u.subclass("esri.views.2d.engine.flow.FlowStrategy")],w);function x(e,t){const o=new y({x:(e.xmax+e.xmin)/2,y:(e.ymax+e.ymin)/2,spatialReference:e.spatialReference}),i=e.xmax-e.xmin,a=e.ymax-e.ymin,n=Math.abs(Math.cos(r.deg2rad(t))),s=Math.abs(Math.sin(r.deg2rad(t))),l=n*i+s*a,c=s*i+n*a,d=new f({xmin:o.x-l/2,ymin:o.y-c/2,xmax:o.x+l/2,ymax:o.y+c/2,spatialReference:e.spatialReference});return d.centerAt(o),d}return w}));
