"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = void 0;

var _propTypes = _interopRequireDefault(require("prop-types"));

var _react = _interopRequireDefault(require("react"));

var _classnames = _interopRequireDefault(require("classnames"));

var _accessibility = require("../../utils/accessibility");

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }

function _extends() { _extends = Object.assign || 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); }

function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }

function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }

var DEFAULT_FILL_COLOR_NAME = "default";

var RangeSlider = function RangeSlider(_ref) {
  var className = _ref.className,
      _ref$fillColorName = _ref.fillColorName,
      fillColorName = _ref$fillColorName === void 0 ? DEFAULT_FILL_COLOR_NAME : _ref$fillColorName,
      _ref$isDisabled = _ref.isDisabled,
      isDisabled = _ref$isDisabled === void 0 ? false : _ref$isDisabled,
      onChange = _ref.onChange,
      testSection = _ref.testSection,
      _ref$useOffForLabel = _ref.useOffForLabel,
      useOffForLabel = _ref$useOffForLabel === void 0 ? false : _ref$useOffForLabel,
      value = _ref.value,
      props = _objectWithoutProperties(_ref, ["className", "fillColorName", "isDisabled", "onChange", "testSection", "useOffForLabel", "value"]);

  var rangeClasses = (0, _classnames["default"])({
    "oui-rangeslider": true,
    "oui-rangeslider--disabled": isDisabled
  }, className); // ensure valid fillColor name (in the case that propType errors are ignored)

  var validFillColorName = Object.keys(_accessibility.FILL_COLOR_MAP).includes(fillColorName) ? fillColorName : DEFAULT_FILL_COLOR_NAME;
  var fillColor = _accessibility.FILL_COLOR_MAP[validFillColorName];
  return _react["default"].createElement("div", _extends({
    className: rangeClasses,
    "data-test-section": testSection
  }, props), _react["default"].createElement("div", {
    className: "oui-grid"
  }, _react["default"].createElement("div", {
    className: "oui-grid__cell position--relative"
  }, _react["default"].createElement("div", {
    className: "range-labels flex"
  }, _react["default"].createElement("label", {
    className: "oui-label muted flush flex--1"
  }, useOffForLabel ? "Off" : "0%"), _react["default"].createElement("label", {
    className: "oui-label muted flush"
  }, "100%")), _react["default"].createElement("div", {
    className: "range-display"
  }, _react["default"].createElement("svg", {
    preserveAspectRatio: "none",
    xmlns: "http://www.w3.org/2000/svg",
    width: "100",
    height: "100",
    viewBox: "0 0 100 100"
  }, _react["default"].createElement("path", {
    fill: fillColor,
    d: "M0 100h100V0z",
    shapeRendering: "geometricPrecision"
  })), _react["default"].createElement("svg", {
    preserveAspectRatio: "none",
    xmlns: "http://www.w3.org/2000/svg",
    width: "100",
    height: "100",
    viewBox: "0 0 100 100",
    style: {
      position: "absolute",
      left: 0,
      top: 0
    }
  }, _react["default"].createElement("path", {
    d: "M".concat(value, " 100H100V0L").concat(value, " ").concat(100 - value - 1, "z"),
    fill: "white",
    opacity: "0.9",
    shapeRendering: "geometricPrecision"
  }))), _react["default"].createElement("div", {
    className: "range-grid"
  }, _react["default"].createElement("div", {
    className: "gridline grid-1"
  }), _react["default"].createElement("div", {
    className: "gridline grid-2"
  }), _react["default"].createElement("div", {
    className: "gridline grid-3"
  }), _react["default"].createElement("div", {
    className: "gridline grid-4"
  }), _react["default"].createElement("div", {
    className: "gridline grid-5"
  }), _react["default"].createElement("div", {
    className: "gridline gridline-half grid-h1"
  }), _react["default"].createElement("div", {
    className: "gridline gridline-half grid-h2"
  }), _react["default"].createElement("div", {
    className: "gridline gridline-half grid-h3"
  }), _react["default"].createElement("div", {
    className: "gridline gridline-half grid-h4"
  })), _react["default"].createElement("input", {
    className: "hard position--relative width--1-1",
    "data-traffic-group": "1",
    type: "range",
    min: "0",
    max: "100",
    step: "1",
    value: value,
    onChange: onChange,
    disabled: isDisabled
  }))));
};

RangeSlider.propTypes = {
  className: _propTypes["default"].string,
  fillColorName: _propTypes["default"].any,
  isDisabled: _propTypes["default"].bool,
  onChange: _propTypes["default"].func.isRequired,
  testSection: _propTypes["default"].string,
  useOffForLabel: _propTypes["default"].bool,
  value: _propTypes["default"].number.isRequired
};
var _default = RangeSlider;
exports["default"] = _default;