function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
import React from 'react';
import { RANGE_SLIDER_TRACK_BELOW_FIRST_THRESHOLD, RANGE_SLIDER_TRACK_BETWEEN_THRESHOLDS, RANGE_SLIDER_TRACK_ABOVE_THRESHOLDS } from './constants';
import { StyledTrackChunk } from './partials/StyledTrackChunk';
var TrackChunk = function TrackChunk(_ref) {
  var getTrackProps = _ref.getTrackProps,
    $left = _ref.$left,
    $width = _ref.$width,
    $maxWidth = _ref.$maxWidth,
    testId = _ref.testId,
    $thresholdColor = _ref.$thresholdColor;
  return /*#__PURE__*/React.createElement(StyledTrackChunk, _extends({
    $thresholdColor: $thresholdColor,
    $left: "".concat($left, "%"),
    $width: "".concat($width, "%"),
    $maxWidth: "".concat($maxWidth, "%")
  }, getTrackProps()));
};
export var ThresholdTrack = function ThresholdTrack(_ref2) {
  var target = _ref2.target,
    getTrackProps = _ref2.getTrackProps,
    thresholds = _ref2.thresholds;
  var singleThreshold = (thresholds === null || thresholds === void 0 ? void 0 : thresholds.length) === 1;
  var doubleThreshold = (thresholds === null || thresholds === void 0 ? void 0 : thresholds.length) === 2;
  return /*#__PURE__*/React.createElement(React.Fragment, null, (singleThreshold || doubleThreshold) && /*#__PURE__*/React.createElement(TrackChunk, {
    $thresholdColor: RANGE_SLIDER_TRACK_BELOW_FIRST_THRESHOLD,
    $left: 0,
    $width: target.percent,
    $maxWidth: thresholds[0],
    getTrackProps: getTrackProps,
    testId: "below-first-threshold"
  }), doubleThreshold && /*#__PURE__*/React.createElement(TrackChunk, {
    $thresholdColor: RANGE_SLIDER_TRACK_BETWEEN_THRESHOLDS,
    $left: thresholds[0],
    $width: Math.max(0, target.percent - thresholds[0]),
    $maxWidth: Math.max(0, target.percent - thresholds[0]),
    getTrackProps: getTrackProps,
    testId: "between-thresholds"
  }), /*#__PURE__*/React.createElement(TrackChunk, {
    $thresholdColor: RANGE_SLIDER_TRACK_ABOVE_THRESHOLDS,
    $left: thresholds[thresholds.length - 1],
    $width: Math.max(0, target.percent - thresholds[thresholds.length - 1]),
    $maxWidth: Math.max(0, target.percent - thresholds[thresholds.length - 1]),
    getTrackProps: getTrackProps,
    testId: "above-thresholds"
  }));
};
ThresholdTrack.displayName = 'ThresholdTrack';