/* COPYRIGHT Esri - https://js.arcgis.com/5.1.2/LICENSE.txt */
import{__decorate as e}from"tslib";import t from"../../core/Accessor.js";import{deprecateUnnecessaryViewModel as i}from"../../core/deprecate.js";import s from"../../core/Error.js";import r from"../../core/Logger.js";import{property as n,subclass as l}from"../../core/accessorSupport/decorators.js";let o=class extends t{constructor(e){super(e),this.precision=4,this.thumbsConstrained=!0,e?.suppressDeprecationWarning||i(r.getLogger(this),"Slider","arcgis-slider",{version:"5.1"})}normalizeCtorArgs(e){const{suppressDeprecationWarning:t,...i}=e;return i}set effectiveMax(e){this.setEffectiveMax(e)}set effectiveMin(e){this.setEffectiveMin(e)}set labelFormatFunction(e){this._set("labelFormatFunction",e)}set inputFormatFunction(e){this._set("inputFormatFunction",e)}set inputParseFunction(e){this._set("inputParseFunction",e)}get labels(){const{max:e,min:t,values:i}=this,s=i?.length?i.map((e,t)=>this.getLabelForValue(e,"value",t)):[];return{max:this.getLabelForValue(e,"max"),min:this.getLabelForValue(t,"min"),values:s}}set max(e){this.setMax(e)}set min(e){this.setMin(e)}get state(){const{max:e,min:t}=this;return null!=e&&null!=t&&e>t?"ready":"disabled"}set values(e){const{max:t,min:i}=this,s=this.values;s&&s.length===e?.length&&s.every((t,i)=>t===e[i])||(this._set("values",null),e?.length&&(null!=i&&e.some(e=>e<i)&&(this.min=Math.min(...e)),null!=t&&e.some(e=>e>t)&&(this.max=Math.max(...e))),this._set("values",e))}toPrecision(e){return parseFloat(e.toFixed(this.precision))}defaultLabelFormatFunction(e){const{max:t,min:i,precision:s}=this,r=null!=t&&null!=i&&t-i>10?2:s;return parseFloat(e.toFixed(r)).toString()}defaultInputFormatFunction(e){return e.toString()}defaultInputParseFunction(e){return parseFloat(e)}getBounds(){const{effectiveMax:e,effectiveMin:t,max:i,min:s}=this;return{min:null!=t&&null!=s?Math.max(s,t):s,max:null!=e&&null!=i?Math.min(i,e):i}}getBoundsForValueAtIndex(e){const{thumbsConstrained:t,values:i}=this,{min:s,max:r}=this.getBounds();if(t&&i){const t=e-1,n=e+1;return{min:null!=i[t]?i[t]:s,max:null!=i[n]?i[n]:r}}return{min:s,max:r}}getLabelForValue(e,t,i){return null==e?null:this.labelFormatFunction?this.labelFormatFunction(e,t,i):this.defaultLabelFormatFunction(e)}setMax(e){const{max:t,values:i}=this;if(null==e)return void this._set("max",null);if(isNaN(e))return void this._logError("slider:invalid-value","Supplied value for property 'max' is NaN.");const s=this.toPrecision(e);if(t!==s)if(null!=this.min&&s<this.min)this._logError("slider:invalid-value","Supplied value for property 'max' is less than 'min'.");else if(this._set("max",s),i?.length)for(let r=0;r<i.length;r++)s<i[r]&&this.setValue(r,s)}setMin(e){const{min:t,values:i}=this;if(null==e)return void this._set("min",null);if(isNaN(e))return void this._logError("slider:invalid-value","Supplied value for property 'min' is NaN.");const s=this.toPrecision(e);if(t!==s)if(null!=this.max&&s>this.max)this._logError("slider:invalid-value","Supplied value for property 'min' is greater than 'max'.");else if(this._set("min",s),i?.length)for(let r=0;r<i.length;r++)s>i[r]&&this.setValue(r,s)}setEffectiveMax(e){if(null==e)return void this._set("effectiveMax",null);if(isNaN(e))return void this._logError("slider:invalid-value","Supplied value for property 'effectiveMax' is NaN.");const t=this.toPrecision(e);this.effectiveMax!==t&&this._set("effectiveMax",this._applyBoundsToValue(t))}setEffectiveMin(e){if(null==e)return void this._set("effectiveMin",null);if(isNaN(e))return void this._logError("slider:invalid-value","Supplied value for property 'effectiveMin' is NaN.");const t=this.toPrecision(e);this.effectiveMin!==t&&this._set("effectiveMin",this._applyBoundsToValue(t))}setValue(e,t){if(isNaN(t))return void this._logError("slider:invalid-value","Supplied value for member of property 'values' is NaN.");const{values:i}=this;if(null==i)return void this._logError("slider:invalid-value","Supplied value for member of property 'values' is null.");const s=i[e],r=this.toPrecision(t);if(s===r)return;const n=[...i];n[e]=r,this._set("values",n)}_applyBoundsToValue(e){const{max:t,min:i}=this;return null!=i&&e<i?i:null!=t&&e>t?t:e}_logError(e,t,i){r.getLogger(this).error(new s(e,t,i))}};e([n()],o.prototype,"effectiveMax",null),e([n()],o.prototype,"effectiveMin",null),e([n()],o.prototype,"labelFormatFunction",null),e([n()],o.prototype,"inputFormatFunction",null),e([n()],o.prototype,"inputParseFunction",null),e([n({readOnly:!0})],o.prototype,"labels",null),e([n()],o.prototype,"max",null),e([n()],o.prototype,"min",null),e([n()],o.prototype,"precision",void 0),e([n({readOnly:!0})],o.prototype,"state",null),e([n()],o.prototype,"thumbsConstrained",void 0),e([n()],o.prototype,"values",null),o=e([l("esri.widgets.Slider.SliderViewModel")],o);const a=o;export{a as default};
