import _inheritsLoose from "@babel/runtime/helpers/esm/inheritsLoose";
var _dec, _class;
import React from 'react';
import { locale } from "../../../lib/locale/decorators";
import { ZIndex } from "../../../internal/ZIndex";
import { ThemeContext } from "../../../lib/theming/ThemeContext";
import { CommonWrapper } from "../../../internal/CommonWrapper";
import { rootNode } from "../../../lib/rootNode";
import { CloseButtonIcon } from "../../../internal/CloseButtonIcon/CloseButtonIcon";
import { cx } from "../../../lib/theming/Emotion";
import { styles } from "../ToastView.styles";
import { ToastDataTids } from "../Toast";
import { ToastLocaleHelper } from "../locale";
export var ToastView = (_dec = locale('Toast', ToastLocaleHelper), rootNode(_class = _dec(_class = /*#__PURE__*/function (_React$Component) {
  function ToastView() {
    var _this;
    for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
      args[_key] = arguments[_key];
    }
    _this = _React$Component.call.apply(_React$Component, [this].concat(args)) || this;
    _this.renderMain = function () {
      var _this$props = _this.props,
        action = _this$props.action,
        showCloseIcon = _this$props.showCloseIcon,
        onClose = _this$props.onClose,
        onMouseEnter = _this$props.onMouseEnter,
        onMouseLeave = _this$props.onMouseLeave,
        use = _this$props.use;
      var toastCloseColors = use === 'error' ? {
        hover: _this.theme.toastCloseHoverColorError,
        "default": _this.theme.toastCloseColorError
      } : {
        hover: _this.theme.toastCloseHoverColor,
        "default": _this.theme.toastCloseColor
      };
      var toastActionColorsClassName = use === 'error' ? styles.toastActionErrorColor(_this.theme) : styles.toastActionDefaultColor(_this.theme);
      var toastActionClassNames = cx(styles.link(_this.theme), toastActionColorsClassName);
      var link = action ? /*#__PURE__*/
      React.createElement("button", {
        "aria-label": action['aria-label'],
        "data-tid": ToastDataTids.action,
        className: toastActionClassNames,
        onClick: action.handler
      }, action.label) : null;
      var close = action || showCloseIcon ? /*#__PURE__*/
      React.createElement("span", {
        className: styles.closeWrapper(_this.theme)
      }, /*#__PURE__*/
      React.createElement(CloseButtonIcon, {
        "aria-label": _this.locale.closeButtonAriaLabel,
        "data-tid": ToastDataTids.close,
        onClick: onClose,
        size: parseInt(_this.theme.toastCloseSize),
        side: 40,
        color: toastCloseColors["default"],
        colorHover: toastCloseColors.hover,
        tabbable: false
      })) : null;
      var rootClassName = cx(styles.root(_this.theme), styles[use != null ? use : 'default'](_this.theme));
      return /*#__PURE__*/(
        React.createElement(CommonWrapper, _this.props, /*#__PURE__*/
        React.createElement(ZIndex, {
          priority: "Toast",
          className: styles.wrapper(_this.theme)
        }, /*#__PURE__*/
        React.createElement("div", {
          "data-tid": ToastDataTids.toastView,
          className: rootClassName,
          ref: _this.setRootNode,
          onMouseEnter: onMouseEnter,
          onMouseLeave: onMouseLeave
        }, /*#__PURE__*/

        React.createElement("span", null, _this.props.children), link, close)))
      );
    };
    return _this;
  }
  _inheritsLoose(ToastView, _React$Component);
  var _proto = ToastView.prototype;
  _proto.render = function render() {
    var _this2 = this;
    return /*#__PURE__*/React.createElement(ThemeContext.Consumer, null, function (theme) {
      _this2.theme = theme;
      return _this2.renderMain();
    });
  };
  return ToastView;
}(React.Component)) || _class) || _class);