'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var _rollupPluginBabelHelpers = require('../../_virtual/_rollupPluginBabelHelpers.js');
var React = require('react');
var Toast_tokens = require('./Toast.tokens.js');
var Toast_styles = require('./Toast.styles.js');
var utils = require('./utils.js');
var ToastProvider = require('./ToastProvider/ToastProvider.js');

function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }

var React__default = /*#__PURE__*/_interopDefault(React);

var _excluded = ["position", "offset", "fade", "text"];
var ToastControllerHoc = function ToastControllerHoc(ToastComponent) {
  return function ToastController(props) {
    var _props$position = props.position,
      position = _props$position === void 0 ? 'bottom' : _props$position,
      offset = props.offset,
      fade = props.fade,
      text = props.text,
      rest = _rollupPluginBabelHelpers.objectWithoutProperties(props, _excluded);
    var _useToastInner = ToastProvider.useToastInner(),
      hideToast = _useToastInner.hideToast,
      isVisible = _useToastInner.isVisible;
    var toastKey = "".concat(text).concat(position);
    var showedClass = isVisible ? Toast_tokens.classes.toastShowed : Toast_tokens.classes.toastHidden;
    var showedFadeClass = isVisible ? Toast_tokens.classes.toastFadeShowed : Toast_tokens.classes.toastFadeHidden;
    var toastProps = _rollupPluginBabelHelpers.objectSpread2({
      text: text,
      onCloseButtonClick: hideToast
    }, rest);
    if (!text) {
      return null;
    }
    return /*#__PURE__*/React__default.default.createElement(React__default.default.Fragment, null, fade && /*#__PURE__*/React__default.default.createElement(Toast_styles.StyledOverlay, {
      className: showedFadeClass,
      zIndex: utils.FADE_Z_INDEX,
      backgroundColorProperty: utils.gradients[position],
      isClickable: false
    }), /*#__PURE__*/React__default.default.createElement(Toast_styles.StyledRoot, {
      key: toastKey,
      position: position,
      offset: offset,
      isVisible: isVisible,
      className: showedClass
    }, /*#__PURE__*/React__default.default.createElement(ToastComponent, toastProps)));
  };
};

exports.ToastControllerHoc = ToastControllerHoc;
