import React from 'react';
import 'react-dom';
import { c as _slicedToArray, e as _extends$1 } from '../_rollupPluginBabelHelpers-539c1155.js';
import 'prop-types';
import 'styled-components';
import '../index-930c2100.js';
import '../hooks/useActivify.js';
import '../overlays/tooltip.js';
import '../key_codes-a5a2b85e.js';
import '../index-6b96e57a.js';
import '@styled-system/space';
import '@styled-system/color';
import '@styled-system/border';
import '@styled-system/variant';
import '@styled-system/typography';
import { s as styleInject } from '../style-inject.es-1f59c1d0.js';
import Icon from '../ui/icon.js';
import '../info-fc9c81b4.js';
import { C as CloseIcon } from '../close-cd95ea58.js';
import '../close-v2-118f2b87.js';
import '../file_placeholder-51e080e8.js';
import '../arrow-e522a0cc.js';
import { S as SuccessIcon } from '../tick-ee41abaf.js';
import '../angle-down-4038e060.js';
import '../checkmark-b6f07b8e.js';
import '../search-da5a95f5.js';
import '../overlays/withTooltip.js';
import Toast from '../overlays/toast.js';

function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
var WarningIcon = (({
  styles = {},
  ...props
}) => React.createElement("svg", _extends({
  xmlns: "http://www.w3.org/2000/svg",
  width: "52",
  height: "48",
  viewBox: "0 0 52 48"
}, props), React.createElement("g", {
  fill: "#FF9800"
}, React.createElement("path", {
  d: "M25.203 30.336c.17.395.452.565.847.565.34 0 .565-.225.79-.623.283-.622.678-2.485 1.13-5.538.453-3.108.678-5.48.678-7.175 0-3.166-.847-4.69-2.6-4.69-1.808 0-2.655 1.582-2.655 4.69 0 2.09.282 4.633.735 7.628.452 2.938.792 4.69 1.075 5.143zm.79 2.937c-.735 0-1.356.283-1.92.848-.566.565-.848 1.187-.848 1.978 0 .735.282 1.412.79 1.92.565.565 1.187.848 1.978.848.735 0 1.412-.283 1.977-.848.565-.565.848-1.188.848-1.92 0-.735-.283-1.356-.848-1.92-.622-.623-1.242-.906-1.977-.906z"
}), React.createElement("path", {
  d: "M50.515 37.059L32.038 4.512C30.796 2.31 28.535.952 25.993.952c-2.543 0-4.803 1.3-6.046 3.56L1.47 37.06c-1.245 2.205-1.187 4.803.055 6.95 1.243 2.148 3.503 3.448 6.046 3.448H44.47c2.485 0 4.745-1.3 6.045-3.448 1.188-2.147 1.245-4.745 0-6.95zm-2.145 5.763c-.848 1.412-2.318 2.26-3.956 2.26H7.571c-1.638 0-3.108-.848-3.956-2.26-.847-1.413-.847-3.108 0-4.578L22.037 5.698c.848-1.47 2.318-2.318 3.956-2.318 1.637 0 3.165.848 3.955 2.318L48.37 38.246c.848 1.413.848 3.108 0 4.576z"
}))));

var css = ".ToastMessage_toastMessage__30gcl {\n  display: flex;\n  align-items: center;\n  padding: 12px; }\n\n.ToastMessage_toastMessageIconError__2QKP3 {\n  margin-right: 4px;\n  width: 32px;\n  height: 32px; }\n  .ToastMessage_toastMessageIconError__2QKP3 svg circle {\n    fill: #f44336; }\n  .ToastMessage_toastMessageIconError__2QKP3 path,\n  .ToastMessage_toastMessageIconError__2QKP3 g {\n    stroke: #fff; }\n\n.ToastMessage_toastMessageIconSuccess__2Pp91 {\n  margin-right: 4px;\n  width: 32px;\n  height: 32px; }\n  .ToastMessage_toastMessageIconSuccess__2Pp91 svg circle {\n    fill: #124fa0; }\n  .ToastMessage_toastMessageIconSuccess__2Pp91 path,\n  .ToastMessage_toastMessageIconSuccess__2Pp91 g {\n    stroke: #fff; }\n\n.ToastMessage_toastMessageIconWarning__2KEGv {\n  margin-right: 8px;\n  width: 24px;\n  height: 24px; }\n";
var styles = {"toastMessage":"ToastMessage_toastMessage__30gcl","toastMessageIconError":"ToastMessage_toastMessageIconError__2QKP3","toastMessageIconSuccess":"ToastMessage_toastMessageIconSuccess__2Pp91","toastMessageIconWarning":"ToastMessage_toastMessageIconWarning__2KEGv"};
styleInject(css);

var TOAST_DEFAULT_TIMEOUT = 2000;

var renderToastIcon = function renderToastIcon(type) {
  switch (type) {
    case "POSITIVE":
      return React.createElement(Icon, {
        className: styles.toastMessageIconSuccess,
        src: SuccessIcon
      });

    case "WARNING":
      return React.createElement(Icon, {
        className: styles.toastMessageIconWarning,
        src: WarningIcon
      });

    default:
      return React.createElement(Icon, {
        className: styles.toastMessageIconError,
        src: CloseIcon
      });
  }
};

var ToastMessage = function ToastMessage() {
  return function (WrappedComponent) {
    return function (props) {
      var _React$useState = React.useState(false),
          _React$useState2 = _slicedToArray(_React$useState, 2),
          toastActive = _React$useState2[0],
          setToastActive = _React$useState2[1];

      var _React$useState3 = React.useState(false),
          _React$useState4 = _slicedToArray(_React$useState3, 2),
          toastMessage = _React$useState4[0],
          setToastMessage = _React$useState4[1];

      var timeout = React.useRef();
      var deactivateToastMessage = React.useCallback(function (e) {
        if (e) {
          e.preventDefault();
          e.stopPropagation();
        }

        if (timeout.current) {
          clearTimeout(timeout.current);
        }

        setToastActive(false);
      });
      var activateToastMessage = React.useCallback(function () {
        var toastMessage = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
        var cb = arguments.length > 1 ? arguments[1] : undefined;

        if (typeof toastMessage === "string") {
          toastMessage = {
            title: toastMessage
          };
        }

        setToastActive(true);
        setToastMessage(toastMessage);
        timeout.current = setTimeout(function () {
          deactivateToastMessage();
          if (cb && typeof cb === "function") cb();
        }, toastMessage.timeout || TOAST_DEFAULT_TIMEOUT);
      });
      React.useEffect(function () {
        return function () {
          return clearTimeout(timeout.current);
        };
      }, []);
      var _toastMessage$title = toastMessage.title,
          title = _toastMessage$title === void 0 ? "Confirm" : _toastMessage$title,
          _toastMessage$type = toastMessage.type,
          type = _toastMessage$type === void 0 ? "NEGATIVE" : _toastMessage$type;
      return React.createElement(React.Fragment, null, React.createElement(WrappedComponent // eslint-disable-next-line react/jsx-props-no-spreading
      , _extends$1({}, props, {
        activateToastMessage: activateToastMessage,
        deactivateToastMessage: deactivateToastMessage,
        toastMessageActive: toastActive
      })), React.createElement(Toast, {
        active: toastActive,
        onOverlayClick: deactivateToastMessage
      }, React.createElement("div", {
        className: styles.toastMessage
      }, renderToastIcon(type), React.createElement("span", {
        className: styles.toastMessageText
      }, title))));
    };
  };
};

export default ToastMessage;
