/*
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{property as t,subclass as n}from"../../core/accessorSupport/decorators.js";import s from"./SmartMappingSliderViewModel.js";let a=class extends s{constructor(e){super(e),this.handlesSyncedToPrimary=!0}set primaryHandleEnabled(e){this._set("primaryHandleEnabled",e)}get primaryHandleEnabled(){const{stops:e}=this;if(!e?.length)return!1;const t=e.length;return(3===t||5===t)&&this._get("primaryHandleEnabled")}get values(){const{primaryHandleEnabled:e,stops:t}=this;if(!t?.length||t.length<2)return[];const n=this.getValuesFromStops();return e?3===n.length?[n[0],n[1],n[2]]:[n[0],n[2],n[4]]:[n[0],n[n.length-1]]}setValue(e,t){const{max:n,min:s,values:a}=this,i=a[e];if(isNaN(t)||i===t||t>n||t<s)return;t=this.toPrecision(t);const r=this.primaryHandleEnabled&&this.handlesSyncedToPrimary;if(r){const n=a.slice().sort((e,t)=>e>t?1:-1)[1];(0===e&&t>n||2===e&&t<n)&&(t=n)}const o=this.getStopChanges(e,t);this.updateStops(o),r?this.notifyChange("values"):(a[e]=t,this._set("values",[...a])),this.notifyChange("labels")}getStopIndexFromValueIndex(e){const{handlesSyncedToPrimary:t,primaryHandleEnabled:n}=this;if(n){const{values:n}=this,s=n[e];if(t)return e;const a=n.slice().sort((e,t)=>e>t?1:-1),i=a.indexOf(s);return n.some((e,t)=>e===s&&t!==i)?a.lastIndexOf(s):i}return super.getStopIndexFromValueIndex(e)}getStopChanges(e,t){return this.primaryHandleEnabled?this._getStopChanges(e,t):super.getStopChanges(e,t)}_getStopChanges(e,t){const{max:n,min:s,stops:a,values:i}=this,r=this.handlesSyncedToPrimary&&1===e,o=i[e],l=i.slice();r||(l[e]=t);const d=l.sort((e,t)=>e>t?1:-1),h=r?t:d[1],p=t-o,u=r?this.toPrecision(Math.max(Math.min(d[0]+p,n),s)):d[0],m=r?this.toPrecision(Math.max(Math.min(d[2]+p,n),s)):d[2];return 5===a.length?[{index:0,value:u},{index:1,value:this.toPrecision((h+u)/2)},{index:2,value:h},{index:3,value:this.toPrecision((h+m)/2)},{index:4,value:m}]:[{index:0,value:u},{index:1,value:h},{index:2,value:m}]}};e([t()],a.prototype,"handlesSyncedToPrimary",void 0),e([t()],a.prototype,"primaryHandleEnabled",null),e([t({dependsOn:["handlesSyncedToPrimary"],readOnly:!0})],a.prototype,"values",null),a=e([n("esri.widgets.smartMapping.SmartMappingPrimaryHandleSliderViewModel")],a);const i=a;export{i as default};
