/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.24/esri/copyright.txt for details.
*/
define(["exports","../../../chunks/_rollupPluginBabelHelpers","../../../core/Error","../../../core/maybe","../../../renderers/support/AuthoringInfo","../../../renderers/support/AuthoringInfoVisualVariable","../../../renderers/support/rasterRendererHelper","../../../renderers/visualVariables/ColorVariable","../../../renderers/visualVariables/OpacityVariable","../../../renderers/visualVariables/SizeVariable","../support/utils","../../renderers/support/utils","../../symbology/flow"],(function(e,a,r,n,t,i,l,o,s,u,m,c,p){"use strict";const d=5;function h(e){return f.apply(this,arguments)}function f(){return(f=a._asyncToGenerator((function*(e){const a={...e};return a.theme||(a.theme="flow-line"),m.processRasterRendererParameters(a)}))).apply(this,arguments)}function y(e){return b.apply(this,arguments)}function b(){return(b=a._asyncToGenerator((function*(e){let a=e.flowScheme,r=null,t=null;const i=yield c.getBasemapInfo(null,e.view);if(r=n.isSome(i.basemapId)?i.basemapId:null,t=n.isSome(i.basemapTheme)?i.basemapTheme:null,a)return{scheme:p.cloneScheme(a),basemapId:r,basemapTheme:t};const l=p.getSchemes({basemap:r,basemapTheme:t,theme:e.theme,hasSizeVariable:e.hasSizeVariable});return l&&(a=l.primaryScheme,r=l.basemapId,t=l.basemapTheme),{scheme:a,basemapId:r,basemapTheme:t}}))).apply(this,arguments)}function w(e,a){return g.apply(this,arguments)}function g(){return(g=a._asyncToGenerator((function*(e,a){a.flowRepresentation&&(e.flowRepresentation=a.flowRepresentation);const r=yield y({theme:a.theme,flowScheme:a.flowScheme,view:a.view,hasSizeVariable:a.includeSizeVariable}),m=r.scheme;if(!m)throw c.createError("flow-renderer:insufficient-info","Unable to find flow scheme");e.flowSpeed=m.flowSpeed,e.density=m.density,e.trailLength=m.trailLength,e.trailWidth=m.trailWidth,e.trailCap=m.trailCap,e.color=m.color;const h=[],f=[],b="Magnitude",w=a.layer.rasterInfo,g=!n.isSome(w.statistics)||"vector-magdir"!==w.dataType&&"vector-uv"!==w.dataType?{minMagnitude:0,maxMagnitude:10}:l.estimateMagnitudeRange(w.dataType,w.statistics);if(!g||null==g.minMagnitude||null==g.maxMagnitude)throw c.createError("flow-renderer:insufficient-info","stats not available");const S={min:g.minMagnitude,max:g.maxMagnitude},V={min:S.min,max:null!=S.max?S.max/2:null},v=c.getDataRange(V,null,null,null),x=c.createDataValues(v,V,null);if(a.includeColorVariable){const e=c.createColors(m.colors,d);if(e.length<d)throw c.createError("flow-renderer:insufficient-info","Flow scheme does not have enough colors");const a=new o({field:b,stops:x.map(((a,r)=>({value:a,color:e[r]})))});h.push(a);const r=new i({type:"color",minSliderValue:S.min,maxSliderValue:S.max,theme:"high-to-low"});f.push(r)}if(a.includeOpacityVariable){const e=new s({field:b,stops:[{value:x[0],opacity:m.minOpacity},{value:x[4],opacity:m.maxOpacity}]});h.push(e);const a=new i({type:"opacity",minSliderValue:S.min,maxSliderValue:S.max});f.push(a)}if(a.includeSizeVariable){const e=new u({field:b,stops:[{value:S.min,size:m.minSize},{value:S.max,size:m.maxSize}]});h.push(e);const a=new i({type:"size",minSliderValue:S.min,maxSliderValue:S.max,theme:"high-to-low"});f.push(a)}const T=new t({type:"flow",visualVariables:f.length?f:null,flowTheme:m.theme});return e.visualVariables=h,e.authoringInfo=T,e.legendOptions=a.legendOptions,{renderer:e,visualVariables:h.map((e=>e.clone())),flowScheme:p.cloneScheme(m),basemapId:r.basemapId,basemapTheme:r.basemapTheme,layerEffect:m.layerEffect,statistics:S}}))).apply(this,arguments)}function S(e){return V.apply(this,arguments)}function V(){return(V=a._asyncToGenerator((function*(e){e=yield h(e);const a=l.createFlowRenderer(e.layer.rasterInfo);if(!n.isSome(a))throw new r("flow-renderer:not-supported","Only vector data is supported");return w(a,e)}))).apply(this,arguments)}e.createRenderer=S,Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
