import { objectWithoutProperties as _objectWithoutProperties, objectSpread2 as _objectSpread2 } from '../../_virtual/_rollupPluginBabelHelpers.js';
import React__default from 'react';
import { classes } from './Toast.tokens.js';
import { StyledOverlay, StyledRoot } from './Toast.styles.js';
import { FADE_Z_INDEX, gradients } from './utils.js';
import { useToastInner } from './ToastProvider/ToastProvider.js';

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 = _objectWithoutProperties(props, _excluded);
    var _useToastInner = useToastInner(),
      hideToast = _useToastInner.hideToast,
      isVisible = _useToastInner.isVisible;
    var toastKey = "".concat(text).concat(position);
    var showedClass = isVisible ? classes.toastShowed : classes.toastHidden;
    var showedFadeClass = isVisible ? classes.toastFadeShowed : classes.toastFadeHidden;
    var toastProps = _objectSpread2({
      text: text,
      onCloseButtonClick: hideToast
    }, rest);
    if (!text) {
      return null;
    }
    return /*#__PURE__*/React__default.createElement(React__default.Fragment, null, fade && /*#__PURE__*/React__default.createElement(StyledOverlay, {
      className: showedFadeClass,
      zIndex: FADE_Z_INDEX,
      backgroundColorProperty: gradients[position],
      isClickable: false
    }), /*#__PURE__*/React__default.createElement(StyledRoot, {
      key: toastKey,
      position: position,
      offset: offset,
      isVisible: isVisible,
      className: showedClass
    }, /*#__PURE__*/React__default.createElement(ToastComponent, toastProps)));
  };
};

export { ToastControllerHoc };
