import React from 'react';
import { IconWarning, IconDangerous } from '@defencedigital/icon-library';
import { RANGE_SLIDER_TRACK_BELOW_FIRST_THRESHOLD, RANGE_SLIDER_TRACK_BETWEEN_THRESHOLDS, RANGE_SLIDER_TRACK_ABOVE_THRESHOLDS } from './constants';
import { StyledRailChunk } from './partials/StyledRailChunk';
var RailChunk = function RailChunk(_ref) {
  var $left = _ref.$left,
    $width = _ref.$width,
    $maxWidth = _ref.$maxWidth,
    testId = _ref.testId,
    $thresholdColor = _ref.$thresholdColor,
    children = _ref.children;
  return /*#__PURE__*/React.createElement(StyledRailChunk, {
    $thresholdColor: $thresholdColor,
    $left: "".concat($left, "%"),
    $width: "".concat($width, "%"),
    $maxWidth: "".concat($maxWidth, "%")
  }, children);
};
export var ThresholdRail = function ThresholdRail(_ref2) {
  var 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(RailChunk, {
    $thresholdColor: RANGE_SLIDER_TRACK_BELOW_FIRST_THRESHOLD,
    $left: 0,
    $width: 100,
    $maxWidth: thresholds[0],
    testId: "below-first-threshold"
  }), doubleThreshold && /*#__PURE__*/React.createElement(RailChunk, {
    $thresholdColor: RANGE_SLIDER_TRACK_BETWEEN_THRESHOLDS,
    $left: thresholds[0],
    $width: Math.max(0, 100 - thresholds[0]),
    $maxWidth: Math.max(0, 100 - thresholds[0]),
    testId: "between-thresholds"
  }, /*#__PURE__*/React.createElement(IconWarning, null)), /*#__PURE__*/React.createElement(RailChunk, {
    $thresholdColor: RANGE_SLIDER_TRACK_ABOVE_THRESHOLDS,
    $left: thresholds[thresholds.length - 1],
    $width: Math.max(0, 100 - thresholds[thresholds.length - 1]),
    $maxWidth: Math.max(0, 100 - thresholds[thresholds.length - 1]),
    testId: "above-thresholds"
  }, /*#__PURE__*/React.createElement(IconDangerous, null)));
};
ThresholdRail.displayName = 'ThresholdRail';