"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var React = require("react");
var SessionContext_1 = require("../SessionContext");
var Localization_1 = require("../Localization");
var Context_1 = require("./Context");
var Fetcher_1 = require("./Fetcher");
var CatalogComponent = function (props) {
    var context = SessionContext_1.useSessionContext();
    var language = Localization_1.useLocalization().language;
    var _a = tslib_1.__read(React.useState(), 2), fetcher = _a[0], setFetcher = _a[1];
    var session = props.session || context.session;
    React.useEffect(function () {
        setFetcher(Fetcher_1.createCatalogFetcher(session, props.catalogRegistrator, language));
    }, [session, language]);
    var contextValue = React.useMemo(function () { return ({
        path: props.path,
        addableTargetId: props.addableTargetId,
        catalogFetcher: fetcher,
    }); }, [props.path, props.addableTargetId, fetcher]);
    if (fetcher === undefined) {
        return null;
    }
    return (React.createElement(Context_1.CatalogContext.Provider, { value: contextValue }, props.children));
};
CatalogComponent.displayName = "CatalogComponent";
exports.default = CatalogComponent;
