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