{"ast":null,"code":"import _defineProperty from \"@babel/runtime/helpers/esm/defineProperty\";\nimport _extends from \"@babel/runtime/helpers/esm/extends\";\nimport _regeneratorRuntime from \"@babel/runtime/regenerator\";\nimport _classCallCheck from \"@babel/runtime/helpers/esm/classCallCheck\";\nimport _createClass from \"@babel/runtime/helpers/esm/createClass\";\nimport _possibleConstructorReturn from \"@babel/runtime/helpers/esm/possibleConstructorReturn\";\nimport _getPrototypeOf from \"@babel/runtime/helpers/esm/getPrototypeOf\";\nimport _inherits from \"@babel/runtime/helpers/esm/inherits\";\nvar __jsx = React.createElement;\n\nfunction ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }\n\nfunction _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }\n\nfunction _createSuper(Derived) { return function () { var Super = _getPrototypeOf(Derived), result; if (_isNativeReflectConstruct()) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }\n\nfunction _isNativeReflectConstruct() { if (typeof Reflect === \"undefined\" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === \"function\") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }\n\n/* eslint-disable @typescript-eslint/no-explicit-any */\nimport { I18nextProvider, withSSR } from 'react-i18next';\nimport { isServer, lngFromReq, lngPathCorrector, lngsToLoad } from '../utils';\nimport { NextStaticProvider } from '../components';\nimport React from 'react';\nimport hoistNonReactStatics from 'hoist-non-react-statics';\nimport { withRouter } from 'next/router';\nexport var appWithTranslation = function appWithTranslation(WrappedComponent) {\n  var WrappedComponentWithSSR = withSSR()(WrappedComponent);\n  var config = this.config,\n      i18n = this.i18n;\n  var consoleMessage = this.consoleMessage.bind(this);\n\n  var clientLoadNamespaces = function clientLoadNamespaces(lng, namespaces) {\n    return Promise.all(namespaces.filter(function (ns) {\n      return !i18n.hasResourceBundle(lng, ns);\n    }).map(function (ns) {\n      return i18n.reloadResources(lng, ns);\n    }));\n  };\n\n  var AppWithTranslation = /*#__PURE__*/function (_React$Component) {\n    _inherits(AppWithTranslation, _React$Component);\n\n    var _super = _createSuper(AppWithTranslation);\n\n    function AppWithTranslation(props) {\n      var _this;\n\n      _classCallCheck(this, AppWithTranslation);\n\n      _this = _super.call(this, props);\n\n      if (!isServer()) {\n        var changeLanguageCallback = function changeLanguageCallback(prevLng, newLng) {\n          var router = props.router;\n          var pathname = router.pathname,\n              asPath = router.asPath,\n              query = router.query;\n          var routeInfo = {\n            pathname: pathname,\n            query: query\n          };\n\n          if (i18n.initializedLanguageOnce && typeof newLng === 'string' && prevLng !== newLng) {\n            var _lngPathCorrector = lngPathCorrector(config, {\n              as: asPath,\n              href: routeInfo\n            }, newLng),\n                as = _lngPathCorrector.as,\n                href = _lngPathCorrector.href;\n\n            router.replace(href, as, {\n              shallow: config.shallowRender\n            });\n          }\n        };\n\n        var changeLanguage = i18n.changeLanguage.bind(i18n);\n\n        i18n.changeLanguage = function _callee(newLng) {\n          var callback,\n              prevLng,\n              usedNamespaces,\n              _args = arguments;\n          return _regeneratorRuntime.async(function _callee$(_context) {\n            while (1) {\n              switch (_context.prev = _context.next) {\n                case 0:\n                  callback = _args.length > 1 && _args[1] !== undefined ? _args[1] : function () {\n                    return null;\n                  };\n                  prevLng = i18n.language;\n\n                  if (!(typeof newLng === 'string' && i18n.initializedLanguageOnce === true)) {\n                    _context.next = 6;\n                    break;\n                  }\n\n                  usedNamespaces = Object.entries(i18n.reportNamespaces.usedNamespaces).filter(function (x) {\n                    return x[1] === true;\n                  }).map(function (x) {\n                    return x[0];\n                  });\n                  _context.next = 6;\n                  return _regeneratorRuntime.awrap(clientLoadNamespaces(newLng, usedNamespaces));\n\n                case 6:\n                  return _context.abrupt(\"return\", changeLanguage(newLng, function () {\n                    changeLanguageCallback(prevLng, newLng);\n                    callback(null, i18n.t);\n                  }));\n\n                case 7:\n                case \"end\":\n                  return _context.stop();\n              }\n            }\n          }, null, null, null, Promise);\n        };\n      }\n\n      return _this;\n    }\n\n    _createClass(AppWithTranslation, [{\n      key: \"render\",\n      value: function render() {\n        var _this$props = this.props,\n            initialLanguage = _this$props.initialLanguage,\n            initialI18nStore = _this$props.initialI18nStore,\n            i18nServerInstance = _this$props.i18nServerInstance;\n        return __jsx(I18nextProvider, {\n          i18n: i18nServerInstance || i18n\n        }, __jsx(NextStaticProvider, null, __jsx(WrappedComponentWithSSR, _extends({\n          initialLanguage: initialLanguage,\n          initialI18nStore: initialI18nStore\n        }, this.props))));\n      }\n    }], [{\n      key: \"getInitialProps\",\n      value: function getInitialProps(ctx) {\n        var wrappedComponentProps, req, initialI18nStore, initialLanguage, i18nServerInstance, router, result, lng, res, setContextLocale, namespacesRequired, fallbackLng, languagesToLoad;\n        return _regeneratorRuntime.async(function getInitialProps$(_context2) {\n          while (1) {\n            switch (_context2.prev = _context2.next) {\n              case 0:\n                wrappedComponentProps = {\n                  pageProps: {}\n                };\n\n                if (!WrappedComponent.getInitialProps) {\n                  _context2.next = 5;\n                  break;\n                }\n\n                _context2.next = 4;\n                return _regeneratorRuntime.awrap(WrappedComponent.getInitialProps(ctx));\n\n              case 4:\n                wrappedComponentProps = _context2.sent;\n\n              case 5:\n                if (typeof wrappedComponentProps.pageProps === 'undefined') {\n                  consoleMessage('error', 'If you have a getInitialProps method in your custom _app.js file, you must explicitly return pageProps. For more information, see: https://github.com/zeit/next.js#custom-app');\n                }\n                /*\n                    Initiate vars to return\n                */\n\n\n                req = ctx.ctx.req;\n                initialI18nStore = {};\n                initialLanguage = null;\n                i18nServerInstance = null;\n\n                if (req && !req.i18n) {\n                  router = ctx.router;\n                  result = router.asPath.match(/^\\/(.*?)\\//);\n                  lng = result ? result[1] : process.env.DEFAULT_LANGUAGE;\n                  req.i18n = i18n.cloneInstance({\n                    initImmediate: false,\n                    lng: lng\n                  });\n                  res = ctx.ctx.res;\n\n                  setContextLocale = function setContextLocale(lng) {\n                    // SEE: i18n-express-middleware\n                    req.language = req.locale = req.lng = lng;\n\n                    if (res) {\n                      res.locals = res.locals || {};\n                      res.locals.language = lng;\n                      res.locals.languageDir = i18n.dir(lng);\n                    }\n                  };\n\n                  setContextLocale(lng);\n                  i18n.on('languageChanged', setContextLocale);\n                }\n                /*\n                    Step 1: Determine initial language\n                */\n\n\n                if (!(req && req.i18n)) {\n                  _context2.next = 17;\n                  break;\n                }\n\n                initialLanguage = lngFromReq(req);\n                /*\n                    Perform a lang change in case we're not on the right lang\n                */\n\n                _context2.next = 15;\n                return _regeneratorRuntime.awrap(req.i18n.changeLanguage(initialLanguage));\n\n              case 15:\n                _context2.next = 18;\n                break;\n\n              case 17:\n                if (Array.isArray(i18n.languages) && i18n.languages.length > 0) {\n                  initialLanguage = i18n.language;\n                }\n\n              case 18:\n                /*\n                    Step 2: Determine namespace dependencies\n                */\n                namespacesRequired = config.ns;\n\n                if (Array.isArray(wrappedComponentProps.pageProps.namespacesRequired)) {\n                  namespacesRequired = wrappedComponentProps.pageProps.namespacesRequired;\n                } else {\n                  consoleMessage('warn', \"You have not declared a namespacesRequired array on your page-level component: \".concat(ctx.Component.displayName || ctx.Component.name || 'Component', \". This will cause all namespaces to be sent down to the client, possibly negatively impacting the performance of your app. For more info, see: https://github.com/isaachinman/next-i18next#4-declaring-namespace-dependencies\"));\n                }\n                /*\n                    We must always send down the defaultNS, otherwise\n                    the client will trigger a request for it and issue\n                    the \"Did not expect server HTML to contain a <h1> in <div>\"\n                    error\n                */\n\n\n                if (typeof config.defaultNS === 'string' && !namespacesRequired.includes(config.defaultNS)) {\n                  namespacesRequired.push(config.defaultNS);\n                }\n                /*\n                    Step 3: Perform data fetching, depending on environment\n                */\n\n\n                if (!(req && req.i18n)) {\n                  _context2.next = 27;\n                  break;\n                }\n\n                /*\n                    Detect the languages to load based upon the fallbackLng configuration\n                */\n                fallbackLng = config.fallbackLng;\n                languagesToLoad = lngsToLoad(initialLanguage, fallbackLng, config.otherLanguages);\n                /*\n                    Initialize the store with the languagesToLoad and\n                    necessary namespaces needed to render this specific tree\n                */\n\n                languagesToLoad.forEach(function (lng) {\n                  initialI18nStore[lng] = {};\n                  namespacesRequired.forEach(function (ns) {\n                    initialI18nStore[lng][ns] = (req.i18n.services.resourceStore.data[lng] || {})[ns] || {};\n                  });\n                });\n                _context2.next = 31;\n                break;\n\n              case 27:\n                if (!(Array.isArray(i18n.languages) && i18n.languages.length > 0)) {\n                  _context2.next = 31;\n                  break;\n                }\n\n                _context2.next = 30;\n                return _regeneratorRuntime.awrap(clientLoadNamespaces(i18n.languages[0], namespacesRequired));\n\n              case 30:\n                initialI18nStore = i18n.store.data;\n\n              case 31:\n                /*\n                    Step 4: Overwrite i18n.toJSON method to be able to serialize the instance\n                */\n                if (req && req.i18n) {\n                  req.i18n.toJSON = function () {\n                    return null;\n                  };\n\n                  i18nServerInstance = req.i18n;\n                }\n                /*\n                    `pageProps` will get serialized automatically by NextJs\n                */\n\n\n                return _context2.abrupt(\"return\", _objectSpread({\n                  initialI18nStore: initialI18nStore,\n                  initialLanguage: initialLanguage,\n                  i18nServerInstance: i18nServerInstance\n                }, wrappedComponentProps));\n\n              case 33:\n              case \"end\":\n                return _context2.stop();\n            }\n          }\n        }, null, null, null, Promise);\n      }\n    }]);\n\n    return AppWithTranslation;\n  }(React.Component);\n\n  return hoistNonReactStatics(withRouter(AppWithTranslation), WrappedComponent, {\n    getInitialProps: true\n  });\n};","map":null,"metadata":{},"sourceType":"module"}