import _extends from "@babel/runtime/helpers/esm/extends";
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
var _excluded = ["children", "type", "iconType", "onClose", "color", "className", "closeButtonLabel", "iconTitle", "iconAriaHidden"];
import * as React from 'react';
import classNames from 'classnames';
import Text, { TEXT_COLOR } from '../text/Text';
import Icon, { TYPE as ICON_TYPE, ICON_COLOR } from '../icons/Icon';
import { __DEV__, invariant } from '../utils';
export var LABEL_TYPE = {
  DEFAULT: 'default',
  SOLID: 'solid',
  TRANSPARENT: 'transparent',
  TRANSPARENT_COLOR: 'transparent-color'
};
export var COLORS_SOLID_MAP = {
  blue: 'blue-60',
  green: 'green-60',
  indigo: 'indigo-60',
  red: 'red-60',
  yellow: 'yellow-40',
  gray: 'gray-40',
  achromatic: 'black'
};
var SOLID_COLOR_TEXT_MAP = {
  blue: 'text-white',
  green: 'text-white',
  indigo: 'text-white',
  red: 'text-white',
  yellow: 'text-black',
  gray: 'text-black',
  achromatic: 'text-white'
};
var SOLID_ICON_COLOR_MAP = {
  blue: 'icon-white',
  green: 'icon-white',
  indigo: 'icon-white',
  red: 'icon-white',
  yellow: 'icon-black',
  gray: 'icon-black',
  achromatic: 'icon-white'
};
export var COLORS_DEFAULT_MAP = {
  blue: 'blue-20',
  green: 'green-20',
  indigo: 'indigo-20',
  red: 'red-20',
  yellow: 'yellow-20',
  gray: 'gray-20',
  achromatic: 'white'
};
var TRANSPARENT_COLOR_TEXT_MAP = {
  blue: 'text-blue-60',
  green: 'text-green-60',
  indigo: 'text-indigo-60',
  red: 'text-red-60',
  yellow: 'text-yellow-60',
  gray: 'text-gray-60',
  achromatic: 'text-black'
};
var TRANSPARENT_ICON_COLOR_MAP = {
  blue: 'icon-blue-50',
  green: 'icon-green-50',
  indigo: 'icon-indigo-50',
  red: 'icon-red-50',
  yellow: 'icon-yellow-50',
  gray: 'icon-gray-50',
  achromatic: 'icon-black'
};
export var LABEL_COLORS_SET = {
  BLUE: 'blue',
  GREEN: 'green',
  INDIGO: 'indigo',
  RED: 'red',
  YELLOW: 'yellow',
  GRAY: 'gray',
  ACHROMATIC: 'achromatic'
};

var Label = function Label(_ref) {
  var _classNames;

  var children = _ref.children,
      _ref$type = _ref.type,
      type = _ref$type === void 0 ? 'default' : _ref$type,
      iconType = _ref.iconType,
      onClose = _ref.onClose,
      _ref$color = _ref.color,
      color = _ref$color === void 0 ? 'achromatic' : _ref$color,
      className = _ref.className,
      closeButtonLabel = _ref.closeButtonLabel,
      iconTitle = _ref.iconTitle,
      iconAriaHidden = _ref.iconAriaHidden,
      props = _objectWithoutProperties(_ref, _excluded);

  if (__DEV__) {
    invariant(!(!iconType && (iconAriaHidden || iconTitle)), 'You cannot hide an icon or name it, when `iconType` s not provided');
    invariant(!(!onClose && closeButtonLabel), // eslint-disable-next-line max-len
    'Button is not rendered when `onClose` is not defined, so it cannot be named');
  }

  var backgroundColor = type === 'default' ? COLORS_DEFAULT_MAP[color] : COLORS_SOLID_MAP[color];
  var labelClass = classNames('sg-label', (_classNames = {}, _defineProperty(_classNames, "sg-label--".concat(String(backgroundColor)), backgroundColor && (type === 'solid' || type === 'default')), _defineProperty(_classNames, 'sg-label--closable', onClose), _defineProperty(_classNames, 'sg-label--transparent', type === 'transparent' || type === 'transparent-color'), _classNames), className);
  var textColor = type === 'default' || type === 'transparent' ? TEXT_COLOR['text-black'] : type === 'solid' ? SOLID_COLOR_TEXT_MAP[color] : TRANSPARENT_COLOR_TEXT_MAP[color];
  var iconColor = type === 'default' ? ICON_COLOR['icon-black'] : type === 'solid' ? SOLID_ICON_COLOR_MAP[color] : TRANSPARENT_ICON_COLOR_MAP[color];
  var closeIconColor = type === 'default' || type === 'transparent' ? ICON_COLOR['icon-black'] : type === 'solid' ? SOLID_ICON_COLOR_MAP[color] : TRANSPARENT_ICON_COLOR_MAP[color];
  return /*#__PURE__*/React.createElement("div", _extends({}, props, {
    className: labelClass
  }), iconType && /*#__PURE__*/React.createElement("div", {
    className: "sg-label__icon"
  }, /*#__PURE__*/React.createElement(Icon, {
    type: iconType,
    color: iconColor,
    size: 16,
    "aria-hidden": iconAriaHidden,
    title: iconTitle
  })), /*#__PURE__*/React.createElement(Text, {
    size: "small",
    weight: "bold",
    color: textColor,
    className: "sg-label__text"
  }, children), onClose ? /*#__PURE__*/React.createElement("button", {
    className: "sg-label__close-button",
    onClick: onClose,
    "aria-label": closeButtonLabel || 'close'
  }, /*#__PURE__*/React.createElement(Icon, {
    type: "close",
    color: closeIconColor,
    size: 16,
    "aria-hidden": true
  })) : null);
};

export default Label;
export { ICON_TYPE };