"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var React = require("react");
var igd_productdata_1 = require("@intelligentgraphics/igd.productdata");
var SessionContext_1 = require("./SessionContext");
var extractLocalization = function (session) { return ({
    language: session.getLanguage(),
    currency: session.getCurrency(),
    locale: session.getLocale(),
    extractLocalizedItemText: function (text) {
        return igd_productdata_1.IGXA.extractLocalizedText(text, session.getLanguage());
    },
}); };
exports.useLocalization = function () {
    var session = SessionContext_1.useSessionContext().session;
    var _a = tslib_1.__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 = exports.useLocalization();
    return props.children(localization);
};
LocalizationSubscription.displayName = "LocalizationSubscription";
exports.default = LocalizationSubscription;
