function _define_property(obj, key, value) {
    if (key in obj) {
        Object.defineProperty(obj, key, {
            value: value,
            enumerable: true,
            configurable: true,
            writable: true
        });
    } else {
        obj[key] = value;
    }
    return obj;
}
function _object_spread(target) {
    for(var i = 1; i < arguments.length; i++){
        var source = arguments[i] != null ? arguments[i] : {};
        var ownKeys = Object.keys(source);
        if (typeof Object.getOwnPropertySymbols === "function") {
            ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
                return Object.getOwnPropertyDescriptor(source, sym).enumerable;
            }));
        }
        ownKeys.forEach(function(key) {
            _define_property(target, key, source[key]);
        });
    }
    return target;
}
function _object_without_properties(source, excluded) {
    if (source == null) return {};
    var target = {}, sourceKeys, key, i;
    if (typeof Reflect !== "undefined" && Reflect.ownKeys) {
        sourceKeys = Reflect.ownKeys(source);
        for(i = 0; i < sourceKeys.length; i++){
            key = sourceKeys[i];
            if (excluded.indexOf(key) >= 0) continue;
            if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
            target[key] = source[key];
        }
        return target;
    }
    target = _object_without_properties_loose(source, excluded);
    if (Object.getOwnPropertySymbols) {
        sourceKeys = Object.getOwnPropertySymbols(source);
        for(i = 0; i < sourceKeys.length; i++){
            key = sourceKeys[i];
            if (excluded.indexOf(key) >= 0) continue;
            if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
            target[key] = source[key];
        }
    }
    return target;
}
function _object_without_properties_loose(source, excluded) {
    if (source == null) return {};
    var target = {}, sourceKeys = Object.getOwnPropertyNames(source), key, i;
    for(i = 0; i < sourceKeys.length; i++){
        key = sourceKeys[i];
        if (excluded.indexOf(key) >= 0) continue;
        if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
        target[key] = source[key];
    }
    return target;
}
import React, { useMemo } from "react";
import { useStoreon } from "storeon/react";
import styled from "styled-components";
import { component } from "../../engines";
import { cx } from "../../utils";
import { PopupProvider, popupConfig, popupClasses } from "../Popup";
import { closeNotification } from "./NotificationsStore";
import { StyledItemWrapper, StyledRoot } from "./Notification.styles";
import { classes } from "./Notification.tokens";
// issue #823
var Popup = component(popupConfig);
var StyledPopup = styled(Popup).withConfig({
    displayName: "NotificationsPortal__StyledPopup",
    componentId: "sc-14d9928e-0"
})([
    "& > .",
    "{overflow:hidden;}"
], popupClasses.root);
/**
 * Обертка для визуального представления уведомлений.
 */ export var NotificationsPortal = function NotificationsPortal(param) {
    var config = param.config, frame = param.frame, _param_placement = param.placement, placement = _param_placement === void 0 ? 'bottom-right' : _param_placement, UNSAFE_SSR_ENABLED = param.UNSAFE_SSR_ENABLED;
    var notifications = useStoreon('notifications').notifications;
    var Notification = useMemo(function() {
        return component(config);
    }, []);
    var hasLeftAnimationClass = [
        'left',
        'bottom-left',
        'top-left'
    ].includes(placement);
    return /*#__PURE__*/ React.createElement(PopupProvider, {
        UNSAFE_SSR_ENABLED: UNSAFE_SSR_ENABLED
    }, notifications.length > 0 && /*#__PURE__*/ React.createElement(StyledPopup, {
        opened: true,
        frame: frame,
        placement: placement,
        zIndex: "9100"
    }, /*#__PURE__*/ React.createElement(StyledRoot, {
        placement: placement
    }, notifications.map(function(_0) {
        var id = _0.id, isHidden = _0.isHidden, rest = _object_without_properties(_0, [
            "id",
            "isHidden"
        ]);
        return /*#__PURE__*/ React.createElement(StyledItemWrapper, {
            key: id,
            className: cx(isHidden ? classes.notificationItemHidden : classes.notificationItemOpened, hasLeftAnimationClass && classes.notificationLeftToRightAnimation, placement === 'top' && classes.notificationTopToCenterAnimation, placement === 'bottom' && classes.notificationBottomToCenterAnimation),
            isHidden: isHidden || false
        }, /*#__PURE__*/ React.createElement(Notification, _object_spread({
            key: id,
            id: id,
            onCloseButtonClick: function onCloseButtonClick() {
                return closeNotification(id);
            }
        }, rest)));
    }))));
};
