"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const react_i18next_1 = require("react-i18next");
const hoist_non_react_statics_1 = __importDefault(require("hoist-non-react-statics"));
const create_config_1 = require("./config/create-config");
const create_i18next_client_1 = __importDefault(require("./create-i18next-client"));
const hocs_1 = require("./hocs");
const utils_1 = require("./utils");
const components_1 = require("./components");
const router_1 = require("./router");
var react_i18next_2 = require("react-i18next");
exports.withTranslation = react_i18next_2.withTranslation;
class NextI18Next {
    constructor(userConfig) {
        this.config = create_config_1.createConfig(userConfig);
        this.consoleMessage = utils_1.consoleMessage.bind(this);
        /* Validation */
        if (this.config.otherLanguages.length <= 0) {
            throw new Error('To properly initialise a next-i18next instance you must provide one or more locale codes in config.otherLanguages.');
        }
        this.withNamespaces = () => {
            throw new Error('next-i18next has upgraded to react-i18next v10 - please rename withNamespaces to withTranslation.');
        };
        const { i18n, initPromise } = create_i18next_client_1.default(this.config);
        this.i18n = i18n;
        this.initPromise = initPromise || Promise.resolve();
        this.appWithTranslation = hocs_1.appWithTranslation.bind(this);
        this.withTranslation = (namespace, options) => Component => hoist_non_react_statics_1.default(react_i18next_1.withTranslation(namespace, options)(Component), Component);
        const nextI18NextInternals = { config: this.config, i18n: this.i18n };
        this.Link = hocs_1.withInternals(components_1.Link, nextI18NextInternals);
        this.Router = router_1.wrapRouter(nextI18NextInternals);
        /* Directly export `react-i18next` methods */
        this.Trans = react_i18next_1.Trans;
        this.useTranslation = react_i18next_1.useTranslation;
    }
}
exports.default = NextI18Next;
