"use strict";var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;exports.__esModule = true;exports.ToastView = void 0;var _inheritsLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/inheritsLoose"));
var _react = _interopRequireDefault(require("react"));

var _decorators = require("../../lib/locale/decorators");

var _ZIndex = require("../../internal/ZIndex");
var _ThemeContext = require("../../lib/theming/ThemeContext");


var _CommonWrapper = require("../../internal/CommonWrapper");

var _rootNode = require("../../lib/rootNode");
var _CloseButtonIcon = require("../../internal/CloseButtonIcon/CloseButtonIcon");
var _Emotion = require("../../lib/theming/Emotion");

var _ToastView2 = require("./ToastView.styles");

var _Toast = require("./Toast");

var _locale = require("./locale");var _dec, _class;var


















ToastView = exports.ToastView = (_dec = (0, _decorators.locale)('Toast', _locale.ToastLocaleHelper), (0, _rootNode.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' ? _ToastView2.styles.toastActionErrorColor(_this.theme) : _ToastView2.styles.toastActionDefaultColor(_this.theme);
      var toastActionClassNames = (0, _Emotion.cx)(_ToastView2.styles.link(_this.theme), toastActionColorsClassName);

      var link = action ? /*#__PURE__*/
      _react.default.createElement("button", {
        "aria-label": action['aria-label'],
        "data-tid": _Toast.ToastDataTids.action,
        className: toastActionClassNames,
        onClick: action.handler },

      action.label
      ) :
      null;

      var close =
      action || showCloseIcon ? /*#__PURE__*/
      _react.default.createElement("span", { className: _ToastView2.styles.closeWrapper(_this.theme) }, /*#__PURE__*/
      _react.default.createElement(_CloseButtonIcon.CloseButtonIcon, {
        "aria-label": _this.locale.closeButtonAriaLabel,
        "data-tid": _Toast.ToastDataTids.close,
        onClick: onClose,
        size: parseInt(_this.theme.toastCloseSize),
        side: 40,
        color: toastCloseColors.default,
        colorHover: toastCloseColors.hover,
        tabbable: false }
      )
      ) :
      null;

      var rootClassName = (0, _Emotion.cx)(_ToastView2.styles.root(_this.theme), _ToastView2.styles[use != null ? use : 'default'](_this.theme));

      return /*#__PURE__*/(
        _react.default.createElement(_CommonWrapper.CommonWrapper, _this.props, /*#__PURE__*/
        _react.default.createElement(_ZIndex.ZIndex, { priority: "Toast", className: _ToastView2.styles.wrapper(_this.theme) }, /*#__PURE__*/
        _react.default.createElement("div", {
          "data-tid": _Toast.ToastDataTids.toastView,
          className: rootClassName,
          ref: _this.setRootNode,
          onMouseEnter: onMouseEnter,
          onMouseLeave: onMouseLeave }, /*#__PURE__*/

        _react.default.createElement("span", null, _this.props.children),
        link,
        close
        )
        )
        ));

    };return _this;}(0, _inheritsLoose2.default)(ToastView, _React$Component);var _proto = ToastView.prototype;_proto.render = function render() {var _this2 = this;return /*#__PURE__*/_react.default.createElement(_ThemeContext.ThemeContext.Consumer, null, function (theme) {_this2.theme = theme;return _this2.renderMain();});};return ToastView;}(_react.default.Component)) || _class) || _class);