import { clamp } from "./clamp.jsx";
import { replaceArrayItemAtIndex } from "./replace-array-item-at-index.jsx";

/**
 * Resolves a candidate slider value for the thumb at `index`, clamping it
 * into `[min, max]` and — for range sliders — into the window bounded by the
 * thumb's immediate neighbours. The return type is scalar or array
 * depending on the `range` flag (matches the React source).
 */
export function getSliderValue(valueInput, index, min, max, range, values) {
  let newValue = valueInput;
  newValue = clamp(newValue, min, max);
  if (range) {
    newValue = replaceArrayItemAtIndex(values, index,
    // Bound the new value to the thumb's neighbours.
    clamp(newValue, values[index - 1] || Number.NEGATIVE_INFINITY, values[index + 1] || Number.POSITIVE_INFINITY));
  }
  return newValue;
}
//# sourceMappingURL=get-slider-value.jsx.map
