"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var React = require("react");
var SessionContext_1 = require("./SessionContext");
var callbackNames = {
    ItemCreated: "onItemCreated",
    ItemChanged: "onItemChanged",
    ItemConfigured: "onItemConfigured",
    ItemGfxInserted: "onItemGfxInserted",
    ItemGfxRemoved: "onItemGfxRemoved",
    ItemRemoved: "onItemRemoved",
};
exports.useNotificationCenterSubscription = function (props) {
    var contextSession = SessionContext_1.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) {
    exports.useNotificationCenterSubscription(props);
    if (props.children !== undefined) {
        return props.children;
    }
    return null;
};
NotificationCenterSubscription.displayName = "NotificationCenterSubscription";
exports.default = SessionContext_1.withSessionContext(NotificationCenterSubscription);
