"use strict";

function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.COLORS_SOLID_MAP = exports.COLORS_DEFAULT_MAP = void 0;
Object.defineProperty(exports, "ICON_TYPE", {
  enumerable: true,
  get: function get() {
    return _Icon.TYPE;
  }
});
exports.default = exports.LABEL_TYPE = exports.LABEL_COLORS_SET = void 0;

var React = _interopRequireWildcard(require("react"));

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

var _Text = _interopRequireWildcard(require("../text/Text"));

var _Icon = _interopRequireWildcard(require("../icons/Icon"));

var _utils = require("../utils");

var _excluded = ["children", "type", "iconType", "onClose", "color", "className", "closeButtonLabel", "iconTitle", "iconAriaHidden"];

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

function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }

function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }

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

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 LABEL_TYPE = {
  DEFAULT: 'default',
  SOLID: 'solid',
  TRANSPARENT: 'transparent',
  TRANSPARENT_COLOR: 'transparent-color'
};
exports.LABEL_TYPE = LABEL_TYPE;
var COLORS_SOLID_MAP = {
  blue: 'blue-60',
  green: 'green-60',
  indigo: 'indigo-60',
  red: 'red-60',
  yellow: 'yellow-40',
  gray: 'gray-40',
  achromatic: 'black'
};
exports.COLORS_SOLID_MAP = COLORS_SOLID_MAP;
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'
};
var COLORS_DEFAULT_MAP = {
  blue: 'blue-20',
  green: 'green-20',
  indigo: 'indigo-20',
  red: 'red-20',
  yellow: 'yellow-20',
  gray: 'gray-20',
  achromatic: 'white'
};
exports.COLORS_DEFAULT_MAP = COLORS_DEFAULT_MAP;
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'
};
var LABEL_COLORS_SET = {
  BLUE: 'blue',
  GREEN: 'green',
  INDIGO: 'indigo',
  RED: 'red',
  YELLOW: 'yellow',
  GRAY: 'gray',
  ACHROMATIC: 'achromatic'
};
exports.LABEL_COLORS_SET = LABEL_COLORS_SET;

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 (_utils.__DEV__) {
    (0, _utils.invariant)(!(!iconType && (iconAriaHidden || iconTitle)), 'You cannot hide an icon or name it, when `iconType` s not provided');
    (0, _utils.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 = (0, _classnames.default)('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.TEXT_COLOR['text-black'] : type === 'solid' ? SOLID_COLOR_TEXT_MAP[color] : TRANSPARENT_COLOR_TEXT_MAP[color];
  var iconColor = type === 'default' ? _Icon.ICON_COLOR['icon-black'] : type === 'solid' ? SOLID_ICON_COLOR_MAP[color] : TRANSPARENT_ICON_COLOR_MAP[color];
  var closeIconColor = type === 'default' || type === 'transparent' ? _Icon.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.default, {
    type: iconType,
    color: iconColor,
    size: 16,
    "aria-hidden": iconAriaHidden,
    title: iconTitle
  })), /*#__PURE__*/React.createElement(_Text.default, {
    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.default, {
    type: "close",
    color: closeIconColor,
    size: 16,
    "aria-hidden": true
  })) : null);
};

var _default = Label;
exports.default = _default;