import _extends from "@babel/runtime/helpers/esm/extends";
import React, { forwardRef, useEffect, useCallback } from "react";
import { StyledToastMessage, StyledToastMessageText, StyledCloseSmallIcon } from "./Styles";
export const ToastMessage = /*#__PURE__*/forwardRef((_ref, ref) => {
  let {
    text,
    type,
    onClose,
    dismissible = false,
    dropShadow = false,
    timeout = 0,
    ...rest
  } = _ref;
  const handleOnClose = useCallback(() => {
    if (typeof onClose === "function") {
      onClose();
    }
  }, [onClose]);
  useEffect(() => {
    if (timeout > 0) {
      const timer = setTimeout(handleOnClose, timeout);
      return () => clearTimeout(timer);
    }
  }, [dismissible, timeout, handleOnClose]);
  return /*#__PURE__*/React.createElement(StyledToastMessage, _extends({
    ref: ref,
    $type: type,
    $dropShadow: dropShadow
  }, rest), /*#__PURE__*/React.createElement(StyledToastMessageText, null, text), dismissible ? /*#__PURE__*/React.createElement(StyledCloseSmallIcon, {
    onClick: handleOnClose
  }) : null);
});
ToastMessage.displayName = "ToastMessage";
//# sourceMappingURL=ToastMessage.js.map