"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.CircledIcon = exports.Icon = void 0;

var _preact = require("preact");

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

var _object = require("./utils/object");

var _pillIcon = _interopRequireDefault(require("./pill-icon"));

var _loadingDotsIcon = require("./loading-dots-icon");

var _liveDotIcon = require("./live-dot-icon");

var _sineWaveIcon = require("./sine-wave-icon");

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); }

const customIcons = {
  pill: _pillIcon.default,
  loading_dots: _loadingDotsIcon.LoadingDots,
  live_dot: _liveDotIcon.LiveDotIcon,
  sine_wave: _sineWaveIcon.SineWaveIcon
};
/**
 * @typedef IconProps
 * @property {string} icon
 * @property {string | number} [size=24] Default is `24`
 * @property {string} [className]
 * @property {number} [speed] Where 0 is stopped 1 is normal speed.
 * @property {any} [style]
 */

/**
 * Icon
 *
 * @type {import('preact').FunctionComponent}
 * @param {IconProps} props
 */

const Icon = props => {
  const {
    icon,
    size,
    className,
    style,
    speed
  } = props;
  const rest = (0, _object.omit)(props, ['icon', 'size', 'className']);
  const px = "".concat(size || 24, "px");
  const styles = Object.assign({}, style, {
    fontSize: px,
    width: px,
    height: px
  });
  const Custom = customIcons[icon];
  return (0, _preact.h)("i", _extends({}, rest, {
    style: styles,
    className: (0, _classnames.default)('dib flex-shrink-0', {
      'material-icons': !Custom
    }, className)
  }), Custom ? (0, _preact.h)(Custom, {
    speed: speed,
    size: size
  }) : icon);
};

exports.Icon = Icon;
const colors = {
  blue: ['bg-lightest-blue', 'blue'],
  yellow: ['bg-light-yellow', 'orange'],
  green: ['bg-light-green', 'dark-green'],
  gray: ['bg-light-gray', 'dark-gray'],
  red: ['bg-light-red', 'dark-red']
};
/**
 * @typedef CircleIconProps
 * @property {string} icon
 * @property {string | number} [size=24] Default is `24`
 * @property {'blue' | 'yellow' | 'green' | 'gray' | 'red'} color
 * @property {number} [speed] Where 0 is stopped 1 is normal speed.
 */

/**
 * CircledIcon
 *
 * @type {import('preact').FunctionComponent}
 * @param {CircleIconProps} props
 */

const CircledIcon = ({
  icon,
  size,
  color,
  speed
}) => {
  size = size ? Number(size) : 24;
  const circleSize = "".concat(Math.round(size * 1.5), "px");
  const matchedColor = colors[color];
  return (0, _preact.h)("div", {
    style: {
      width: circleSize,
      height: circleSize
    },
    className: (0, _classnames.default)('inline-flex items-center justify-center br-100 flex-shrink-0', matchedColor && matchedColor[0])
  }, (0, _preact.h)(Icon, {
    icon: icon,
    size: size,
    speed: speed,
    className: (0, _classnames.default)(matchedColor && matchedColor[1])
  }));
};

exports.CircledIcon = CircledIcon;