"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

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

var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));

var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));

var _react = _interopRequireDefault(require("react"));

var _uiIcons = require("@teamleader/ui-icons");

var _box = _interopRequireDefault(require("../box"));

var _button = _interopRequireDefault(require("../button"));

var _buttonGroup = _interopRequireDefault(require("../buttonGroup"));

var _icon = _interopRequireDefault(require("../icon"));

var _iconButton = require("../iconButton");

var _typography = require("../typography");

var _excluded = ["children", "inline", "onClose", "primaryAction", "secondaryAction", "showIcon", "status", "title"];
var iconColorMap = {
  error: 'neutral',
  info: 'neutral',
  success: 'neutral',
  warning: 'gold'
};
var iconTintMap = {
  error: 'lightest',
  info: 'darkest',
  success: 'lightest',
  warning: 'dark'
};
var backgroundColorMap = {
  error: 'ruby',
  info: 'neutral',
  success: 'mint',
  warning: 'gold'
};
var backgroundTintMap = {
  error: 'normal',
  info: 'normal',
  success: 'light',
  warning: 'light'
};
var iconMap = {
  error: _uiIcons.IconWarningBadgedMediumFilled,
  info: _uiIcons.IconBellMediumOutline,
  success: _uiIcons.IconCheckmarkBadgedMediumFilled,
  warning: _uiIcons.IconWarningBadgedMediumFilled
};

var Message = function Message(_ref) {
  var children = _ref.children,
      inline = _ref.inline,
      onClose = _ref.onClose,
      primaryAction = _ref.primaryAction,
      secondaryAction = _ref.secondaryAction,
      showIcon = _ref.showIcon,
      _ref$status = _ref.status,
      status = _ref$status === void 0 ? 'info' : _ref$status,
      title = _ref.title,
      others = (0, _objectWithoutProperties2.default)(_ref, _excluded);
  var hasActions = Boolean(primaryAction || secondaryAction);
  var IconToRender = iconMap[status];
  return /*#__PURE__*/_react.default.createElement(_box.default, (0, _extends2.default)({}, others, {
    display: inline ? 'inline-flex' : 'flex'
  }), status && /*#__PURE__*/_react.default.createElement(_box.default, {
    backgroundColor: backgroundColorMap[status],
    backgroundTint: backgroundTintMap[status],
    borderBottomLeftRadius: "rounded",
    borderTopLeftRadius: "rounded",
    paddingHorizontal: showIcon ? 2 : 1,
    paddingVertical: 4
  }, showIcon && /*#__PURE__*/_react.default.createElement(_icon.default, {
    color: iconColorMap[status],
    tint: iconTintMap[status]
  }, /*#__PURE__*/_react.default.createElement(IconToRender, null))), /*#__PURE__*/_react.default.createElement(_box.default, {
    backgroundColor: "neutral",
    backgroundTint: "lightest",
    borderColor: "neutral",
    borderTint: "normal",
    borderLeftWidth: status ? 0 : 1,
    borderTopWidth: 1,
    borderRightWidth: 1,
    borderBottomWidth: 1,
    borderBottomRightRadius: "rounded",
    borderTopRightRadius: "rounded",
    borderBottomLeftRadius: status ? 'square' : 'rounded',
    borderTopLeftRadius: status ? 'square' : 'rounded',
    flex: 1,
    display: "flex"
  }, /*#__PURE__*/_react.default.createElement(_box.default, {
    flex: 1,
    paddingLeft: status ? 3 : 4,
    paddingRight: 4,
    paddingVertical: 4
  }, title && /*#__PURE__*/_react.default.createElement(_typography.Heading3, {
    color: "teal",
    marginBottom: 2
  }, title), children, hasActions && /*#__PURE__*/_react.default.createElement(_buttonGroup.default, {
    display: "flex",
    justifyContent: "flex-end",
    marginTop: 4
  }, secondaryAction && /*#__PURE__*/_react.default.createElement(_button.default, (0, _extends2.default)({
    level: "link",
    size: "small"
  }, secondaryAction)), primaryAction && /*#__PURE__*/_react.default.createElement(_button.default, (0, _extends2.default)({
    size: "small"
  }, primaryAction)))), onClose && /*#__PURE__*/_react.default.createElement(_box.default, {
    paddingVertical: 4,
    paddingRight: 3
  }, /*#__PURE__*/_react.default.createElement(_iconButton.IconButton, {
    icon: /*#__PURE__*/_react.default.createElement(_uiIcons.IconCloseMediumOutline, null),
    marginLeft: -2,
    marginTop: -1,
    onClick: onClose
  }))));
};

var _default = Message;
exports.default = _default;