import * as React from "react";
import { useSessionContext } from "../SessionContext";
import { useLocalization } from "../Localization";
import { CatalogContext } from "./Context";
import { createCatalogFetcher } from "./Fetcher";
const CatalogComponent = props => {
    const context = useSessionContext();
    const { language } = useLocalization();
    const [fetcher, setFetcher] = React.useState();
    const session = props.session || context.session;
    React.useEffect(() => {
        setFetcher(createCatalogFetcher(session, props.catalogRegistrator, language));
    }, [session, language]);
    const contextValue = React.useMemo(() => ({
        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;
