"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = exports.BarScale = void 0;
var _range2 = _interopRequireDefault(require("ramda/src/range"));
var _react = _interopRequireDefault(require("react"));
var _styledComponents = _interopRequireDefault(require("styled-components"));
var _utils = require("../../common/utils");
var _ = require("../..");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var Indicator = (0, _styledComponents.default)(_.Box).withConfig({
  displayName: "BarScale__Indicator",
  componentId: "sc-15hgyor-0"
})(["height:", "px;background:", ";border-radius:", ";"], function (p) {
  return p.theme.spacing.unit(p.$barHeight);
}, function (p) {
  return p.$isActive ? p.theme.colorTokens.action.background_data_risk : p.theme.colorTokens.neutral.background_strong;
}, function (p) {
  return p.theme.borderRadius(1);
});
var BarScale = exports.BarScale = function BarScale(_ref) {
  var _R$range;
  var _ref$value = _ref.value,
    value = _ref$value === void 0 ? 0 : _ref$value,
    _ref$max = _ref.max,
    max = _ref$max === void 0 ? 7 : _ref$max,
    _ref$axisLabel = _ref.axisLabel,
    axisLabel = _ref$axisLabel === void 0 ? null : _ref$axisLabel,
    _ref$barHeight = _ref.barHeight,
    barHeight = _ref$barHeight === void 0 ? 3 : _ref$barHeight,
    _ref$gutter = _ref.gutter,
    gutter = _ref$gutter === void 0 ? 1 : _ref$gutter;
  var verifiedMaxRating = (0, _utils.isNumber)(max) ? max : 7;
  var clampedValue = (0, _utils.isNumber)(value) ? Math.max(0, Math.min(value, max)) : 0;
  var isActive = function isActive(bar) {
    return bar <= clampedValue;
  };
  return _react.default.createElement(_react.default.Fragment, null, _react.default.createElement(_.Flexbox, {
    container: true,
    gap: gutter
  }, (_R$range = (0, _range2.default)(1, verifiedMaxRating + 1)) === null || _R$range === void 0 ? void 0 : _R$range.map(function (bar) {
    return _react.default.createElement(_.Flexbox, {
      key: bar,
      item: true,
      flex: "1 1 auto"
    }, _react.default.createElement(Indicator, {
      $isActive: isActive(bar),
      $barHeight: barHeight
    }));
  })), axisLabel);
};
var _default = exports.default = BarScale;