"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.RANGE_SLIDER_SIZES = void 0;
exports.default = RangeSlider;
var _react = _interopRequireWildcard(require("react"));
require("rheostat/initialize");
var _rheostat = _interopRequireDefault(require("rheostat"));
var _classnames = _interopRequireDefault(require("classnames"));
var _utils = _interopRequireDefault(require("./utils"));
var _defaultHandle = require("./default-handle");
var _context = require("./context");
var _jsxRuntime = require("react/jsx-runtime");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
const RANGE_SLIDER_SIZES = exports.RANGE_SLIDER_SIZES = {
  MD: 'md',
  LG: 'lg',
  XL: 'xl'
};
const hasMultipleValues = values => values.length > 1;
const isInRange = (values, children) => hasMultipleValues(values) ? children >= values[0] && children <= values[values.length - 1] : children <= values[0];
const DefaultPitComponent = ({
  style,
  children,
  values
}) => /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
  className: `pit-component${isInRange(values, children) ? ' in-range' : ''}`
  /* eslint-disable-next-line react/forbid-dom-props */,
  style: style
});

/** Customization logic for DR deployments */
function CustomizedDefaultProgressBar({
  defaultProps,
  customOptions
}) {
  return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
    ...customOptions,
    children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_rheostat.default.defaultProps.progressBar, {
      ...defaultProps
    })
  });
}

/**
 * RangeSlider - A range slider component, built on https://github.com/airbnb/rheostat
 * @midnight-gray-supported
 * @alpine-light-supported
 */
function RangeSlider({
  values,
  onValuesUpdated,
  min,
  max,
  pitPoints,
  snapPoints,
  snap,
  pitComponent,
  progressBar,
  handle = _defaultHandle.DefaultHandle,
  onChange,
  onSliderDragStart,
  onSliderDragEnd,
  isDisabled,
  algorithm,
  customizedDefaultProgressBar,
  size = RANGE_SLIDER_SIZES.MD,
  testId,
  handleAriaLabel,
  handleAriaValueText,
  ariaLabelledBy,
  ...rest
}) {
  (0, _react.useEffect)(() => {
    if (snap && !snapPoints && process.env.NODE_ENV === 'development') {
      // eslint-disable-next-line no-console
      console.error(`[RangeSlider] snap is enabled without snapPoints, keyboard navigation is broken`);
    }
  }, []);
  const ariaContext = (0, _react.useMemo)(() => ({
    handleAriaLabel,
    handleAriaValueText,
    ariaLabelledBy,
    testId
  }), [handleAriaLabel, handleAriaValueText, testId]);
  return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
    "test-id": "range-slider",
    className: (0, _classnames.default)('range-slider', {
      disabled: isDisabled
    }, size),
    children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_context.AriaContext.Provider, {
      value: ariaContext,
      children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_rheostat.default, {
        handle: handle,
        pitComponent: _utils.default.withProps(pitComponent || DefaultPitComponent, {
          values
        }),
        progressBar: customizedDefaultProgressBar ? defaultProps => CustomizedDefaultProgressBar({
          defaultProps,
          customOptions: customizedDefaultProgressBar
        }) : progressBar,
        values: values,
        algorithm: algorithm,
        onValuesUpdated: onValuesUpdated,
        min: min,
        max: max,
        pitPoints: pitPoints,
        snap: snap,
        snapPoints: snapPoints,
        onChange: onChange,
        onSliderDragStart: onSliderDragStart,
        onSliderDragEnd: onSliderDragEnd,
        disabled: isDisabled,
        ...rest
      })
    })
  });
}