"use strict";

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

var _typeof = require("@babel/runtime/helpers/typeof");

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 _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));

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

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

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

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

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

var _propTypes = _interopRequireDefault(require("prop-types"));

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"];

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 _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2.default)(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2.default)(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2.default)(this, result); }; }

function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }

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 iconColorMap = {
  error: 'neutral',
  info: 'neutral',
  success: 'neutral',
  warning: 'gold'
};
var iconTintMap = {
  error: 'lightest',
  info: 'darkest',
  success: 'lightest',
  warning: 'dark'
};
/** @type {React.ComponentType<any>} */

var Message = /*#__PURE__*/function (_PureComponent) {
  (0, _inherits2.default)(Message, _PureComponent);

  var _super = _createSuper(Message);

  function Message() {
    (0, _classCallCheck2.default)(this, Message);
    return _super.apply(this, arguments);
  }

  (0, _createClass2.default)(Message, [{
    key: "render",
    value: function render() {
      var _this$props = this.props,
          children = _this$props.children,
          inline = _this$props.inline,
          onClose = _this$props.onClose,
          primaryAction = _this$props.primaryAction,
          secondaryAction = _this$props.secondaryAction,
          showIcon = _this$props.showIcon,
          status = _this$props.status,
          title = _this$props.title,
          others = (0, _objectWithoutProperties2.default)(_this$props, _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
      }))));
    }
  }]);
  return Message;
}(_react.PureComponent);

var _default = Message;
exports.default = _default;