import _extends from "@babel/runtime/helpers/extends";
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
import _createClass from "@babel/runtime/helpers/createClass";
import _inherits from "@babel/runtime/helpers/inherits";
import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
var _excluded = ["children", "inline", "onClose", "primaryAction", "secondaryAction", "showIcon", "status", "title"];

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

import React, { PureComponent } from 'react';
import PropTypes from 'prop-types';
import { IconBellMediumOutline, IconCheckmarkBadgedMediumFilled, IconCloseMediumOutline, IconWarningBadgedMediumFilled } from '@teamleader/ui-icons';
import Box from '../box';
import Button from '../button';
import ButtonGroup from '../buttonGroup';
import Icon from '../icon';
import { IconButton } from '../iconButton';
import { Heading3 } from '../typography';
var backgroundColorMap = {
  error: 'ruby',
  info: 'neutral',
  success: 'mint',
  warning: 'gold'
};
var backgroundTintMap = {
  error: 'normal',
  info: 'normal',
  success: 'light',
  warning: 'light'
};
var iconMap = {
  error: IconWarningBadgedMediumFilled,
  info: IconBellMediumOutline,
  success: IconCheckmarkBadgedMediumFilled,
  warning: 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) {
  _inherits(Message, _PureComponent);

  var _super = _createSuper(Message);

  function Message() {
    _classCallCheck(this, Message);

    return _super.apply(this, arguments);
  }

  _createClass(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 = _objectWithoutProperties(_this$props, _excluded);

      var hasActions = Boolean(primaryAction || secondaryAction);
      var IconToRender = iconMap[status];
      return /*#__PURE__*/React.createElement(Box, _extends({}, others, {
        display: inline ? 'inline-flex' : 'flex'
      }), status && /*#__PURE__*/React.createElement(Box, {
        backgroundColor: backgroundColorMap[status],
        backgroundTint: backgroundTintMap[status],
        borderBottomLeftRadius: "rounded",
        borderTopLeftRadius: "rounded",
        paddingHorizontal: showIcon ? 2 : 1,
        paddingVertical: 4
      }, showIcon && /*#__PURE__*/React.createElement(Icon, {
        color: iconColorMap[status],
        tint: iconTintMap[status]
      }, /*#__PURE__*/React.createElement(IconToRender, null))), /*#__PURE__*/React.createElement(Box, {
        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.createElement(Box, {
        flex: 1,
        paddingLeft: status ? 3 : 4,
        paddingRight: 4,
        paddingVertical: 4
      }, title && /*#__PURE__*/React.createElement(Heading3, {
        color: "teal",
        marginBottom: 2
      }, title), children, hasActions && /*#__PURE__*/React.createElement(ButtonGroup, {
        display: "flex",
        justifyContent: "flex-end",
        marginTop: 4
      }, secondaryAction && /*#__PURE__*/React.createElement(Button, _extends({
        level: "link",
        size: "small"
      }, secondaryAction)), primaryAction && /*#__PURE__*/React.createElement(Button, _extends({
        size: "small"
      }, primaryAction)))), onClose && /*#__PURE__*/React.createElement(Box, {
        paddingVertical: 4,
        paddingRight: 3
      }, /*#__PURE__*/React.createElement(IconButton, {
        icon: /*#__PURE__*/React.createElement(IconCloseMediumOutline, null),
        marginLeft: -2,
        marginTop: -1,
        onClick: onClose
      }))));
    }
  }]);

  return Message;
}(PureComponent);

export default Message;