"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _react = require("react");
var _classnames = _interopRequireDefault(require("classnames"));
var _reactTransitionGroup = require("react-transition-group");
var _Toast = _interopRequireDefault(require("../Toast"));
var _jsxRuntime = require("react/jsx-runtime");
// Copyright 1999-2023. Plesk International GmbH. All rights reserved.

const ToastView = _ref => {
  let {
    toasts,
    onToastClose,
    position,
    baseClassName
  } = _ref;
  let stack = toasts;
  if (position === 'bottom-end') {
    stack = [...stack];
    stack.reverse();
  }
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactTransitionGroup.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__*/(0, _react.createRef)();
      return /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactTransitionGroup.CSSTransition, {
        classNames: `${baseClassName}__toast-`,
        timeout: {
          enter: 300,
          exit: 300
        },
        nodeRef: toastRef,
        children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_Toast.default, {
          ...toastProps,
          autoClosable: autoClosable,
          onClose: () => onToastClose({
            ...toastProps,
            key
          }),
          innerRef: toastRef,
          className: (0, _classnames.default)(toastProps.className, `${baseClassName}__toast`)
        })
      }, key);
    })
  });
};
var _default = exports.default = ToastView;