"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = void 0;

var _i18next = _interopRequireDefault(require("i18next"));

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }

function getNameSpace(ns) {
  var lang = _i18next["default"].language;
  return new Promise(function (resolve, reject) {
    if (ns && lang) {
      var exists = _i18next["default"].hasResourceBundle(lang, ns);

      if (!exists) {
        _i18next["default"].loadNamespaces(ns).then(function () {
          resolve(_i18next["default"].getFixedT(null, ns));
        });
      } else {
        resolve(_i18next["default"].getFixedT(null, ns));
      }
    } else {
      reject();
    }
  });
}

function noop() {
  return _i18next["default"].getFixedT(null, 'MkGlobal');
}

function getLocalNs(ns, reactInstance) {
  var lang = _i18next["default"].language;

  if (ns && lang) {
    var exists = _i18next["default"].hasResourceBundle(lang, ns);

    if (!exists) {
      _i18next["default"].loadNamespaces(ns).then(function () {
        if (reactInstance && typeof reactInstance.setState === 'function') {
          // setTimeout(() => { reactInstance.setState(reactInstance.state); }, 500)
          reactInstance.setState(reactInstance.state);
        }
      });
    }
  }

  return _i18next["default"].getFixedT(null, ns);
}

var _default = {
  getNameSpace: getNameSpace,
  getLocalNs: getLocalNs,
  noop: noop
}; // import React from 'react';
// import { ConfigConsumer } from 'maycur-antd/lib/config-provider';
// const LocalWrap = Component = (props) => {
//     return (<ConfigConsumer>
//         {config => {
//             console.log(config)
//             return <Component {...props} config={config}></Component>
//         }
//         }
//     </ConfigConsumer>)
// }
// export default LocalWrap;

exports["default"] = _default;