/*
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 r from"../../Color.js";import{property as s,cast as t,subclass as i}from"../../core/accessorSupport/decorators.js";import a from"../../renderers/support/ClassBreakInfo.js";import l from"./SmartMappingSliderBase.js";import o from"./ClassedSizeSlider/ClassedSizeSliderViewModel.js";import{getFillFromColor as n}from"./support/utils.js";import{globalCss as m}from"../support/globalCss.js";import{messageBundle as p,tsx as d}from"../support/widget.js";import{storeNode as c}from"../support/widgetUtils.js";var h;const u="esri-classed-size-slider",b={base:u,rampElement:`${u}__ramp`,sliderContainer:`${u}__slider-container`,histogramContainer:`${u}__histogram-container`,track:`${u}--interactive-track`},g={trackFillColor:new r([149,149,149]),trackBackgroundColor:new r([224,224,224])};let k=h=class extends l{constructor(e,r){super(e,r),this._rampNode=null,this.messages=null,this.style={...g},this.viewModel=new o}get breaks(){return this.viewModel.breaks}set breaks(e){this.viewModel.breaks=e}get label(){return this.messages?.widgetLabel??""}set label(e){this._overrideIfSome("label",e)}castStyle(e){return{...g,...e}}static fromRendererResult(e,r){const{renderer:{classBreakInfos:s}}=e,t=s.map(e=>{const r=e.symbol;let s;switch(r.type){case"simple-line":s=r.width;break;case"simple-marker":s=r.size;break;case"picture-marker":s=r.height}return{min:e.minValue,max:e.maxValue,size:s}});return new h({breaks:t,histogramConfig:{bins:r?r.bins:[]}})}updateClassBreakInfos(e){const r=this.breaks;if(r.length===e.length)return e.map((e,s)=>{const t=e.symbol;switch(t.type){case"simple-line":t.width=r[s].size;break;case"simple-marker":t.size=r[s].size;break;case"picture-marker":{const e=r[s].size,i=t.width,a=t.height;t.height=e,t.width=e/a*i;break}}return new a({minValue:r[s].min,maxValue:r[s].max,symbol:t})});console.error(`Number of input breakInfos must match number of slider breaks: ${r.length}`)}updateFromRendererResult(e,r){const{renderer:{classBreakInfos:s}}=e,t=s.map(e=>{const r=e.symbol;let s;switch(r.type){case"simple-line":s=r.width;break;case"simple-marker":s=r.size;break;case"picture-marker":s=r.height}return{min:e.minValue,max:e.maxValue,size:s}});this.set({breaks:t}),r?.bins&&(this.histogramConfig.bins=r.bins)}render(){const{state:e,label:r,visibleElements:s}=this,t="disabled"===e,i=this.classes(b.base,m.widget,m.panel,{[m.disabled]:t,[b.track]:!!s.interactiveTrack});return d("div",{"aria-label":r,class:i},t?null:this.renderContent(this._renderRamp(),b.sliderContainer,b.histogramContainer))}_renderRamp(){const{style:{trackBackgroundColor:e}}=this;return d("div",{afterCreate:c,bind:this,class:b.rampElement,"data-node-ref":"_rampNode"},d("svg",{xmlns:"http://www.w3.org/2000/svg"},d("rect",{fill:n(e),height:"100%",width:"100%",x:"0",y:"0"}),this._renderPath()))}_renderPath(){if(!this._rampNode)return;const{offsetHeight:e=0,offsetWidth:r=0}=this._rampNode;if(null==e||null==r)return;const{breaks:s,viewModel:{max:t,min:i},style:{trackFillColor:a}}=this,l=t-i,o=r/s.length,m=s.map(r=>e-Math.round((r.min-i)/l*e)+1).reverse(),p=s[0].size>s[s.length-1].size||!1;let c=p?o:r,h=`M${c} 0 `;return m.forEach((e,s)=>{const t=o*(s+1);h+=`L${c} ${e} `,c=p?o+t:r-t,h+=`L${c} ${e} `}),h+=`L0 ${e} L0 ${e} L0 0 Z`,d("path",{d:h,fill:n(a)})}};e([s()],k.prototype,"breaks",null),e([s()],k.prototype,"label",null),e([s(),p("esri/widgets/smartMapping/ClassedSizeSlider/t9n/ClassedSizeSlider")],k.prototype,"messages",void 0),e([s()],k.prototype,"style",void 0),e([t("style")],k.prototype,"castStyle",null),e([s({type:o})],k.prototype,"viewModel",void 0),k=h=e([i("esri.widgets.smartMapping.ClassedSizeSlider")],k);const f=k;export{f as default};
