import * as React from "react";
import { IGXA } from "@intelligentgraphics/igd.productdata";
import { useSessionContext } from "./SessionContext";
const extractLocalization = (session) => ({
    language: session.getLanguage(),
    currency: session.getCurrency(),
    locale: session.getLocale(),
    extractLocalizedItemText: text => IGXA.extractLocalizedText(text, session.getLanguage()),
});
export const useLocalization = () => {
    const { session } = useSessionContext();
    const [state, setState] = React.useState(extractLocalization(session));
    React.useEffect(() => {
        setState(extractLocalization(session));
        const subscription = session.on("LocalizationChanged", () => extractLocalization(session));
        return subscription.destroy;
    }, [session]);
    return state;
};
const LocalizationSubscription = props => {
    const localization = useLocalization();
    return props.children(localization);
};
LocalizationSubscription.displayName = "LocalizationSubscription";
export default LocalizationSubscription;
