"use strict";
/*
  This `Router` is a wrap of the standard
  NextJs `Router`, with some simple lang
  redirect logic in place.

  If you haven't already, read this issue comment:
  https://github.com/zeit/next.js/issues/2833#issuecomment-414919347

  Very important: if you import `Router` from NextJs directly,
  and not this file, your lang subpath routing will break.
*/
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
/* eslint-disable @typescript-eslint/no-explicit-any */
const router_1 = __importDefault(require("next/router"));
const utils_1 = require("../utils");
const propertyFields = ['pathname', 'route', 'query', 'asPath', 'components', 'events'];
const coreMethods = ['reload', 'back', 'beforePopState', 'ready', 'prefetch'];
const wrappedMethods = ['push', 'replace'];
exports.wrapRouter = (nextI18NextInternals) => {
    const Router = {};
    propertyFields.forEach(field => {
        Object.defineProperty(Router, field, {
            get() {
                return router_1.default[field];
            }
        });
    });
    coreMethods.forEach(method => {
        Router[method] = (...args) => router_1.default[method](...args);
    });
    wrappedMethods.forEach(method => {
        Router[method] = (path, as, options) => {
            const { config, i18n } = nextI18NextInternals;
            if (utils_1.subpathIsRequired(config, i18n.languages[0])) {
                const { as: correctedAs, href: correctedHref } = utils_1.lngPathCorrector(config, { as, href: path }, i18n.languages[0]);
                return router_1.default[method](correctedHref, correctedAs, options);
            }
            return router_1.default[method](path, as, options);
        };
    });
    return Router;
};
