// Copyright 1999-2023. Plesk International GmbH. All rights reserved.

import { createRef } from 'react';
import classNames from 'classnames';
import { TransitionGroup, CSSTransition } from 'react-transition-group';
import Toast from '../Toast';
import { jsx as _jsx } from "react/jsx-runtime";
const ToastView = _ref => {
  let {
    toasts,
    onToastClose,
    position,
    baseClassName
  } = _ref;
  let stack = toasts;
  if (position === 'bottom-end') {
    stack = [...stack];
    stack.reverse();
  }
  return /*#__PURE__*/_jsx(TransitionGroup, {
    component: "span",
    className: baseClassName,
    children: stack.map(_ref2 => {
      let {
        key,
        ...toastProps
      } = _ref2;
      const {
        intent
      } = toastProps;
      let {
        autoClosable
      } = toastProps;
      if (autoClosable === undefined && intent === 'success' && position === 'top-end') {
        autoClosable = true;
      }
      const toastRef = /*#__PURE__*/createRef();
      return /*#__PURE__*/_jsx(CSSTransition, {
        classNames: `${baseClassName}__toast-`,
        timeout: {
          enter: 300,
          exit: 300
        },
        nodeRef: toastRef,
        children: /*#__PURE__*/_jsx(Toast, {
          ...toastProps,
          autoClosable: autoClosable,
          onClose: () => onToastClose({
            ...toastProps,
            key
          }),
          innerRef: toastRef,
          className: classNames(toastProps.className, `${baseClassName}__toast`)
        })
      }, key);
    })
  });
};
export default ToastView;