text: "use strict";
  var __extends = (this && this.__extends) || (function () {
      var extendStatics = function (d, b) {
          extendStatics = Object.setPrototypeOf ||
              ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
              function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
          return extendStatics(d, b);
      };
      return function (d, b) {
          extendStatics(d, b);
          function __() { this.constructor = d; }
          d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
      };
  })();
  var __importStar = (this && this.__importStar) || function (mod) {
      if (mod && mod.__esModule) return mod;
      var result = {};
      if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
      result["default"] = mod;
      return result;
  };
  var __importDefault = (this && this.__importDefault) || function (mod) {
      return (mod && mod.__esModule) ? mod : { "default": mod };
  };
  Object.defineProperty(exports, "__esModule", { value: true });
  var react_1 = __importStar(require("react"));
  var node_polyglot_1 = __importDefault(require("node-polyglot"));
  var react_redux_1 = require("react-redux");
  var ra_language_english_1 = __importDefault(require("ra-language-english"));
  var defaultsDeep_1 = __importDefault(require("lodash/defaultsDeep"));
  var TranslationContext_1 = require("./TranslationContext");
  /**
   * Creates a translation context, available to its children
   *
   * Must be called within a Redux app.
   *
   * @example
   *     const MyApp = () => (
   *         <Provider store={store}>
   *             <TranslationProvider locale="fr" messages={messages}>
   *                 <!-- Child components go here -->
   *             </TranslationProvider>
   *         </Provider>
   *     );
   */
  var TranslationProviderView = /** @class */ (function (_super) {
      __extends(TranslationProviderView, _super);
      function TranslationProviderView(props) {
          var _this = _super.call(this, props) || this;
          var locale = props.locale, messages = props.messages;
          var polyglot = new node_polyglot_1.default({
              locale: locale,
              phrases: defaultsDeep_1.default({ '': '' }, messages, ra_language_english_1.default),
          });
          _this.state = {
              contextValues: {
                  locale: locale,
                  translate: polyglot.t.bind(polyglot),
              },
          };
          return _this;
      }
      TranslationProviderView.prototype.componentDidUpdate = function (prevProps) {
          if (prevProps.locale !== this.props.locale ||
              prevProps.messages !== this.props.messages) {
              var _a = this.props, locale = _a.locale, messages = _a.messages;
              var polyglot = new node_polyglot_1.default({
                  locale: locale,
                  phrases: defaultsDeep_1.default({ '': '' }, messages, ra_language_english_1.default),
              });
              this.setState({
                  contextValues: {
                      locale: locale,
                      translate: polyglot.t.bind(polyglot),
                  },
              });
          }
      };
      TranslationProviderView.prototype.render = function () {
          var children = this.props.children;
          var contextValues = this.state.contextValues;
          return (react_1.default.createElement(TranslationContext_1.TranslationContext.Provider, { value: contextValues }, react_1.Children.only(children)));
      };
      return TranslationProviderView;
  }(react_1.Component));
  var mapStateToProps = function (state) { return ({
      locale: state.i18n.locale,
      messages: state.i18n.messages,
  }); };
  var TranslationProvider = react_redux_1.connect(mapStateToProps)(TranslationProviderView);
  exports.default = TranslationProvider;
  