import * as React from "react";
import { withSessionContext, useSessionContext, } from "./SessionContext";
var callbackNames = {
    ItemCreated: "onItemCreated",
    ItemChanged: "onItemChanged",
    ItemConfigured: "onItemConfigured",
    ItemGfxInserted: "onItemGfxInserted",
    ItemGfxRemoved: "onItemGfxRemoved",
    ItemRemoved: "onItemRemoved",
};
export var useNotificationCenterSubscription = function (props) {
    var contextSession = useSessionContext().session;
    var session = props.session || contextSession;
    var currentProps = React.useRef(props);
    currentProps.current = props;
    React.useEffect(function () {
        var subscription = session.onAnyEvent(function (event) {
            var callbackName = callbackNames[event.event];
            if (callbackName !== undefined) {
                var callback = currentProps.current[callbackName];
                if (callback !== undefined) {
                    callback(event.data);
                }
            }
        });
        return function () { return subscription.destroy(); };
    }, [session]);
};
var NotificationCenterSubscription = function (props) {
    useNotificationCenterSubscription(props);
    if (props.children !== undefined) {
        return props.children;
    }
    return null;
};
NotificationCenterSubscription.displayName = "NotificationCenterSubscription";
export default withSessionContext(NotificationCenterSubscription);
