"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports.default = void 0;
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
var _react = _interopRequireWildcard(require("react"));
var _framerMotion = require("framer-motion");
var _ToastContext = require("../Toast/ToastContext");
var _ToastContainerSt = require("./ToastContainer.st.css.js");
var _jsxFileName = "/home/builduser/work/57e038ea7326c1ec/packages/wix-design-system/dist/cjs/ToastContainer/ToastContainer.tsx";
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
var toastTransition = {
  duration: 0.3,
  ease: [0, 0, 0.2, 1]
};
var noTransition = {
  duration: 0
};
var initialState = {
  opacity: 0,
  transition: {
    duration: 0.3,
    ease: [0.4, 0, 1, 1]
  }
};
var multiToastInitialState = _objectSpread({
  translateY: '100%'
}, initialState);
var toastVisibleState = {
  translateY: '0%',
  opacity: 1,
  transition: {
    duration: 0.3,
    ease: [0.4, 0, 1, 1]
  }
};
var toastHiddenState = {
  translateY: '0%',
  opacity: 0
};
var multiToastExitedState = {
  translateY: '0%',
  opacity: 0,
  transition: {
    duration: 0.3,
    ease: [0.4, 0, 1, 1]
  }
};
var toastExitState = {
  opacity: 0
};
var ToastContainer = /*#__PURE__*/(0, _react.forwardRef)((_ref, ref) => {
  var {
    offset,
    zIndex,
    dataHook,
    position,
    maxToasts = 1,
    className,
    children
  } = _ref;
  var toasts = _react.default.Children.toArray(children).reverse();
  var getAnimationState = () => {
    var transition = maxToasts === 1 ? noTransition : toastTransition;
    var initial = maxToasts === 1 ? initialState : multiToastInitialState;
    var exit = maxToasts === 1 ? toastExitState : multiToastExitedState;
    return {
      transition,
      initial,
      exit
    };
  };
  return /*#__PURE__*/_react.default.createElement("div", {
    ref: ref,
    className: (0, _ToastContainerSt.st)(_ToastContainerSt.classes.root, className),
    "data-hook": dataHook,
    style: {
      bottom: offset,
      zIndex,
      position: position || 'fixed'
    },
    __self: void 0,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 72,
      columnNumber: 7
    }
  }, /*#__PURE__*/_react.default.createElement(_framerMotion.AnimatePresence, {
    __self: void 0,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 79,
      columnNumber: 9
    }
  }, toasts.map((toast, index) => {
    if (! /*#__PURE__*/(0, _react.isValidElement)(toast)) {
      return null;
    }
    var hidden = index >= maxToasts;
    var containerKey = "toast-container-".concat(toast.key);
    var {
      transition,
      initial,
      exit
    } = getAnimationState();
    return /*#__PURE__*/_react.default.createElement(_framerMotion.motion.div, {
      key: containerKey,
      "data-hook": containerKey,
      "data-hidden": hidden,
      layout: true,
      transition: transition,
      initial: initial,
      animate: hidden ? toastHiddenState : toastVisibleState,
      exit: exit,
      style: {
        pointerEvents: hidden ? 'none' : undefined
      },
      __self: void 0,
      __source: {
        fileName: _jsxFileName,
        lineNumber: 90,
        columnNumber: 15
      }
    }, /*#__PURE__*/_react.default.createElement(_ToastContext.ToastContext.Provider, {
      value: {
        hidden
      },
      __self: void 0,
      __source: {
        fileName: _jsxFileName,
        lineNumber: 103,
        columnNumber: 17
      }
    }, toast));
  })));
});
ToastContainer.displayName = 'ToastContainer';
var _default = exports.default = ToastContainer;
//# sourceMappingURL=ToastContainer.js.map