"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.Thumb = exports.TickBar = exports.Tick = exports.AxisRange = exports.Axis = exports.Root = void 0;

var _index = require("../styles/index.js");

var _icons = require("./icons.js");

function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; var ownKeys = Object.keys(source); if (typeof Object.getOwnPropertySymbols === 'function') { ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) { return Object.getOwnPropertyDescriptor(source, sym).enumerable; })); } ownKeys.forEach(function (key) { _defineProperty(target, key, source[key]); }); } return target; }

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

var Root = (0, _index.styled)('div', function (props) {
  return {
    paddingTop: '1px',
    position: 'relative'
  };
});
exports.Root = Root;
Root.displayName = "Root";
Root.displayName = 'StyledRoot';
var Axis = (0, _index.styled)('div', function (props) {
  var $theme = props.$theme;
  var colors = $theme.colors,
      borders = $theme.borders,
      sizing = $theme.sizing;
  return {
    position: 'relative',
    marginTop: sizing.scale900,
    marginBottom: sizing.scale900,
    marginRight: sizing.scale400,
    marginLeft: sizing.scale400,
    borderRadius: $theme.borders.useRoundedCorners ? borders.radius100 : '0px',
    backgroundColor: colors.mono400,
    height: sizing.scale100
  };
});
exports.Axis = Axis;
Axis.displayName = "Axis";
Axis.displayName = 'StyledAxis';
var AxisRange = (0, _index.styled)('div', function (props) {
  var $max = props.$max,
      $min = props.$min,
      $index = props.$index,
      $isRange = props.$isRange,
      $value = props.$value,
      $theme = props.$theme;
  var colors = $theme.colors,
      borders = $theme.borders,
      sizing = $theme.sizing;
  var fillColor = colors.primary400;
  var emptyColor = colors.mono400;
  var barColor;

  if ($isRange) {
    barColor = $index % 2 === 0 ? emptyColor : fillColor;
  } else {
    barColor = $index % 2 === 0 ? fillColor : emptyColor;
  }

  var value = $isRange && $index ? $value[$index] - $value[$index - 1] : $value[$index];
  var totalRangeValue = $max - $min;
  var width = "".concat(value / totalRangeValue * 100, "%");
  var offset = $isRange && $index ? "".concat($value[$index - 1] / totalRangeValue * 100, "%") : null;
  return {
    borderRadius: borders.useRoundedCorners ? sizing.scale0 : '0',
    height: '100%',
    position: 'absolute',
    top: '0',
    marginLeft: offset,
    backgroundColor: barColor,
    width: width
  };
});
exports.AxisRange = AxisRange;
AxisRange.displayName = "AxisRange";
AxisRange.displayName = 'StyledAxisRange';
var Tick = (0, _index.styled)('div', function (props) {
  return {};
});
exports.Tick = Tick;
Tick.displayName = "Tick";
Tick.displayName = 'StyledTick';
var TickBar = (0, _index.styled)('div', function (props) {
  var $theme = props.$theme;
  var sizing = $theme.sizing;
  return {
    display: 'flex',
    justifyContent: 'space-between',
    alignItems: 'center',
    marginTop: sizing.scale400,
    marginBottom: sizing.scale400,
    marginRight: sizing.scale400,
    marginLeft: sizing.scale400
  };
});
exports.TickBar = TickBar;
TickBar.displayName = "TickBar";
TickBar.displayName = 'StyledTickBar';
var Thumb = (0, _index.styled)('div', function (props) {
  var $theme = props.$theme,
      $value = props.$value,
      $max = props.$max,
      $index = props.$index,
      $currentThumb = props.$currentThumb,
      $disabled = props.$disabled,
      $isRange = props.$isRange;
  var $isActive = $index === $currentThumb;
  var offset = Math.round($value[$index] / $max * 100);
  var animation = $theme.animation,
      colors = $theme.colors,
      sizing = $theme.sizing;
  var backgroundColor = $disabled ? colors.mono500 : colors.white;
  var thumbColor = getThumbColor(_objectSpread({}, props, {
    $isActive: $isActive
  }));
  var toggleSVG = '';
  var $isStart = $isRange && $index % 2 === 0;
  var $isEnd = $isRange && $index % 2 !== 0;

  if ($isStart) {
    toggleSVG = (0, _icons.startThumbIcon)(backgroundColor, thumbColor);
  } else if ($isEnd) {
    toggleSVG = (0, _icons.endThumbIcon)(backgroundColor, thumbColor);
  } else {
    toggleSVG = (0, _icons.singleThumbIcon)(backgroundColor, thumbColor);
  }

  return {
    transitionDuration: animation.timing100,
    transitionTimingFunction: animation.easeOutCurve,
    transitionProperty: 'background-color',
    ':after': {
      position: 'absolute',
      content: "url('data:image/svg+xml;utf8,".concat(toggleSVG, "')")
    },
    position: 'relative',
    top: '-14px',
    cursor: 'pointer',
    zIndex: '1',
    left: "".concat(offset, "%"),
    marginLeft: $isRange ? '-8px' : $index % 2 ? '-32px' : '-16px',
    ':before': {
      position: 'absolute',
      content: "\"".concat(Math.round($value[$index]), "\""),
      top: '-14px',
      marginLeft: sizing.scale100,
      width: sizing.scale600,
      height: sizing.scale600
    }
  };
});
exports.Thumb = Thumb;
Thumb.displayName = "Thumb";
Thumb.displayName = 'StyledThumb';

function getThumbColor(props) {
  var $disabled = props.$disabled,
      $isFocused = props.$isFocused,
      $isError = props.$isError,
      $isHovered = props.$isHovered,
      $isActive = props.$isActive,
      $theme = props.$theme;
  var colors = $theme.colors;

  if ($disabled) {
    return colors.mono600;
  } else if ($isActive || $isFocused || $isHovered) {
    return colors.primary400;
  } else if ($isError) {
    if ($isActive || $isFocused) {
      return colors.negative200;
    } else if ($isHovered) {
      return colors.negative100;
    } else {
      return colors.negative50;
    }
  } else {
    return colors.mono600;
  }
}