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