"use strict";
Object.defineProperty(exports, "__esModule", {
    value: true
});
Object.defineProperty(exports, "NotificationsPortal", {
    enumerable: true,
    get: function() {
        return NotificationsPortal;
    }
});
const _react = /*#__PURE__*/ _interop_require_wildcard(require("react"));
const _react1 = require("storeon/react");
const _styled = /*#__PURE__*/ _interop_require_default(require("@emotion/styled"));
const _engines = require("../../engines");
const _utils = require("../../utils");
const _Popup = require("../Popup");
const _NotificationsStore = require("./NotificationsStore");
const _Notificationstyles = require("./Notification.styles");
const _Notificationtokens = require("./Notification.tokens");
function _interop_require_default(obj) {
    return obj && obj.__esModule ? obj : {
        default: obj
    };
}
function _getRequireWildcardCache(nodeInterop) {
    if (typeof WeakMap !== "function") return null;
    var cacheBabelInterop = new WeakMap();
    var cacheNodeInterop = new WeakMap();
    return (_getRequireWildcardCache = function(nodeInterop) {
        return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
    })(nodeInterop);
}
function _interop_require_wildcard(obj, nodeInterop) {
    if (!nodeInterop && obj && obj.__esModule) {
        return obj;
    }
    if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
        return {
            default: obj
        };
    }
    var cache = _getRequireWildcardCache(nodeInterop);
    if (cache && cache.has(obj)) {
        return cache.get(obj);
    }
    var newObj = {
        __proto__: null
    };
    var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
    for(var key in obj){
        if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
            var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
            if (desc && (desc.get || desc.set)) {
                Object.defineProperty(newObj, key, desc);
            } else {
                newObj[key] = obj[key];
            }
        }
    }
    newObj.default = obj;
    if (cache) {
        cache.set(obj, newObj);
    }
    return newObj;
}
// issue #823
const Popup = (0, _engines.component)(_Popup.popupConfig);
const StyledPopup = /*#__PURE__*/ (0, _styled.default)(Popup, {
    target: "el7fuu0",
    label: "StyledPopup"
})("& > .", _Popup.popupClasses.root, "{overflow:hidden;}");
const NotificationsPortal = ({ config, frame, placement = 'bottom-right', UNSAFE_SSR_ENABLED, className })=>{
    const { notifications } = (0, _react1.useStoreon)('notifications');
    const Notification = (0, _react.useMemo)(()=>(0, _engines.component)(config), []);
    const hasLeftAnimationClass = [
        'left',
        'bottom-left',
        'top-left'
    ].includes(placement);
    return /*#__PURE__*/ _react.default.createElement(_Popup.PopupProvider, {
        UNSAFE_SSR_ENABLED: UNSAFE_SSR_ENABLED
    }, notifications.length > 0 && /*#__PURE__*/ _react.default.createElement(StyledPopup, {
        opened: true,
        frame: frame,
        placement: placement,
        zIndex: "9100"
    }, /*#__PURE__*/ _react.default.createElement(_Notificationstyles.StyledRoot, {
        placement: placement,
        className: className
    }, notifications.map(({ id, isHidden, ...rest })=>/*#__PURE__*/ _react.default.createElement(_Notificationstyles.StyledItemWrapper, {
            key: id,
            className: (0, _utils.cx)(isHidden ? _Notificationtokens.classes.notificationItemHidden : _Notificationtokens.classes.notificationItemOpened, hasLeftAnimationClass && _Notificationtokens.classes.notificationLeftToRightAnimation, placement === 'top' && _Notificationtokens.classes.notificationTopToCenterAnimation, placement === 'bottom' && _Notificationtokens.classes.notificationBottomToCenterAnimation),
            isHidden: isHidden || false
        }, /*#__PURE__*/ _react.default.createElement(Notification, {
            key: id,
            id: id,
            onCloseButtonClick: ()=>(0, _NotificationsStore.closeNotification)(id),
            ...rest
        }))))));
};
