import { __read } from "tslib";
import * as React from "react";
import { useSessionContext } from "../SessionContext";
import { useLocalization } from "../Localization";
import { CatalogContext } from "./Context";
import { createCatalogFetcher } from "./Fetcher";
var CatalogComponent = function (props) {
    var context = useSessionContext();
    var language = useLocalization().language;
    var _a = __read(React.useState(), 2), fetcher = _a[0], setFetcher = _a[1];
    var session = props.session || context.session;
    React.useEffect(function () {
        setFetcher(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(CatalogContext.Provider, { value: contextValue }, props.children));
};
CatalogComponent.displayName = "CatalogComponent";
export default CatalogComponent;
