import { __read } from "tslib";
import * as React from "react";
import { useSessionContext } from "./SessionContext";
export var useArticleSubscription = function (comId) {
    var session = useSessionContext().session;
    var _a = __read(React.useState(function () {
        return comId === undefined ? undefined : session.getArticleByComId(comId);
    }), 2), article = _a[0], setArticle = _a[1];
    React.useEffect(function () {
        var update = function (article) {
            if (article.comId === comId) {
                setArticle(session.getArticleByComId(comId));
            }
        };
        var subscription = session.subscribe({
            ItemCreated: update,
            ItemConfigured: update,
            ItemRemoved: update,
            ItemGfxInserted: update,
        });
        return function () { return subscription.destroy(); };
    }, [comId]);
    return article;
};
var ArticleSubscription = function (props) {
    var article = useArticleSubscription(props.comId);
    return props.children({ article: article });
};
ArticleSubscription.displayName = "ArticleSubscription";
export default ArticleSubscription;
