/*
All material copyright Esri, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/5.0/esri/copyright.txt for details.
*/
import{__decorate as e}from"tslib";import t from"../../Color.js";import{property as s,cast as i,subclass as r}from"../../core/accessorSupport/decorators.js";import{authoringInfoFirstVariableSliderMinMax as a}from"../../renderers/support/authoringInfoUtils.js";import o from"../../renderers/visualVariables/SizeVariable.js";import l from"../../renderers/visualVariables/support/SizeStop.js";import n from"./SmartMappingSliderBase.js";import d from"./SizeSlider/SizeSliderViewModel.js";import{getSizesFromVariable as p,getFillFromColor as m,getDynamicPathForSizeStops as u,getPathForSizeStops as h}from"./support/utils.js";import{globalCss as c}from"../support/globalCss.js";import{messageBundle as v,tsx as g}from"../support/widget.js";import{storeNode as b}from"../support/widgetUtils.js";var y;const f="esri-size-slider",z={base:f,rampElement:`${f}__ramp`,sliderContainer:`${f}__slider-container`,histogramContainer:`${f}__histogram-container`,primaryHandle:`${f}--primary-handle`,track:`${f}--interactive-track`},w={trackFillColor:new t([149,149,149]),trackBackgroundColor:new t([224,224,224])};let S=y=class extends n{constructor(e,t){super(e,t),this._maxRampFillWidth=1,this._minRampFillWidth=.2,this._rampNode=null,this.messages=null,this.style={...w},this.viewModel=new d,this.viewModel=new d}get handlesSyncedToPrimary(){return this.viewModel.handlesSyncedToPrimary}set handlesSyncedToPrimary(e){this.viewModel.handlesSyncedToPrimary=e}get label(){return this.messages?.widgetLabel??""}set label(e){this._overrideIfSome("label",e)}get persistSizeRangeEnabled(){return this.viewModel.persistSizeRangeEnabled}set persistSizeRangeEnabled(e){this.viewModel.persistSizeRangeEnabled=e}get primaryHandleEnabled(){return this.viewModel.primaryHandleEnabled}set primaryHandleEnabled(e){this.viewModel.primaryHandleEnabled=e}get stops(){return this.viewModel.stops}set stops(e){this.viewModel.stops=e}castStyle(e){return{...w,...e}}static fromRendererResult(e,t){const{visualVariables:s,statistics:i}=e,{avg:r,stddev:o}=i,n=s[0],[d,m]=p(n),[u,h]=a(e.renderer.authoringInfo);return new y({max:h,min:u,stops:[new l({value:n.minDataValue??void 0,size:m}),new l({value:n.maxDataValue??void 0,size:d})],histogramConfig:{average:r??void 0,standardDeviation:o??void 0,bins:t?t.bins:[]}})}updateFromRendererResult(e,t){const{visualVariables:s,statistics:i}=e,{avg:r,stddev:o}=i,l=s[0],[n,d]=p(l),[m,u]=a(e.renderer.authoringInfo);this.set({max:u,min:m,stops:[{value:l.minDataValue,size:d},{value:l.maxDataValue,size:n}],histogramConfig:{average:r,standardDeviation:o,bins:t?t.bins:[]}})}updateVisualVariable(e){const t=e.clone(),{stops:s}=this;if(!e||!s)return null;if(t.stops)return t.stops=s,t;const i=s[0],r=s[s.length-1];let a=t.maxSize,l=t.minSize;if(a instanceof o){const e=a.stops,t=r.size/e[0].size,s=e.map(e=>(e.size*=t,e));a.stops=s}else a=r.size;if(l instanceof o){const e=l.stops,t=i.size/e[0].size,s=e.map(e=>(e.size*=t,e));l.stops=s}else l=i.size;return t.set({maxDataValue:r.value,minDataValue:i.value,maxSize:a,minSize:l}),t}updateFromVisualVariable(e){if(!e)return;const{maxDataValue:t,minDataValue:s,stops:i}=e;if(i)this.stops=i;else{const[i,r]=p(e);this.stops=[new l({value:s??void 0,size:r}),new l({value:t??void 0,size:i})]}}render(){const{label:e,primaryHandleEnabled:t,state:s,visibleElements:i}=this,r="disabled"===s,a=this.classes(z.base,c.widget,c.panel,{[c.disabled]:r,[z.primaryHandle]:t,[z.track]:!!i.interactiveTrack});return g("div",{"aria-label":e,class:a},r?null:this.renderContent(this._renderRamp(),z.sliderContainer,z.histogramContainer))}_renderRamp(){const{style:{trackBackgroundColor:e},zoomOptions:t}=this;return g("div",{afterCreate:b,bind:this,class:z.rampElement,"data-node-ref":"_rampNode"},g("svg",{key:"ramp-svg",xmlns:"http://www.w3.org/2000/svg"},g("rect",{fill:m(e),height:"100%",width:"100%",x:"0",y:"0"}),this._renderPath()),t?this.renderZoomCaps():null)}_renderPath(){if(!this._rampNode)return;const{offsetHeight:e=0,offsetWidth:t=0}=this._rampNode;if(null==e||null==t)return;const{primaryHandleEnabled:s,stops:i,style:{trackFillColor:r},values:a,viewModel:{max:o,min:l},_maxRampFillWidth:n,_minRampFillWidth:d}=this,p=[n,d];i[0].size<i[i.length-1].size&&p.reverse();const c=a.slice().sort((e,t)=>e>t?1:-1),[v,b]=p,[y,f]=c,z=s?u({max:o,min:l,pathHeight:e,pathWidth:t,stops:i,padding:b}):h({bottomValue:y,bottomWidth:v,max:o,min:l,pathHeight:e,pathWidth:t,topValue:f,topWidth:b});return g("path",{d:z,fill:m(r)})}};e([s()],S.prototype,"handlesSyncedToPrimary",null),e([s()],S.prototype,"label",null),e([s(),v("esri/widgets/smartMapping/SizeSlider/t9n/SizeSlider")],S.prototype,"messages",void 0),e([s()],S.prototype,"persistSizeRangeEnabled",null),e([s()],S.prototype,"primaryHandleEnabled",null),e([s()],S.prototype,"stops",null),e([s()],S.prototype,"style",void 0),e([i("style")],S.prototype,"castStyle",null),e([s({type:d})],S.prototype,"viewModel",void 0),S=y=e([r("esri.widgets.smartMapping.SizeSlider")],S);const V=S;export{V as default};
