"use strict";

var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

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

var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));

var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));

var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));

var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));

var _getPrototypeOf3 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));

var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));

var _react = _interopRequireWildcard(require("react"));

var _propTypes = _interopRequireDefault(require("prop-types"));

var _formatMessageGenerateId = _interopRequireDefault(require("format-message-generate-id"));

var _LocaleSwitcher = _interopRequireDefault(require("quiz-interactions/lib/util/LocaleSwitcher"));

var _formatMessage = _interopRequireDefault(require("@instructure/quiz-common/lib/format-message"));

var generateId = _formatMessageGenerateId.default.underscored_crc32; // This is for switching locales in the docs app. Not for production use!

var LocaleSwitcher =
/*#__PURE__*/
function (_Component) {
  (0, _inherits2.default)(LocaleSwitcher, _Component);

  function LocaleSwitcher() {
    var _getPrototypeOf2;

    var _this;

    (0, _classCallCheck2.default)(this, LocaleSwitcher);

    for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
      args[_key] = arguments[_key];
    }

    _this = (0, _possibleConstructorReturn2.default)(this, (_getPrototypeOf2 = (0, _getPrototypeOf3.default)(LocaleSwitcher)).call.apply(_getPrototypeOf2, [this].concat(args)));

    _this.handleLocaleChange = function (locale, translations) {
      _formatMessage.default.setup({
        generateId: generateId,
        locale: locale,
        translations: (0, _defineProperty2.default)({}, locale, translations)
      });
    };

    return _this;
  }

  (0, _createClass2.default)(LocaleSwitcher, [{
    key: "render",
    value: function render() {
      return _react.default.createElement(_LocaleSwitcher.default, {
        onLocaleChange: this.handleLocaleChange
      }, this.props.children);
    }
  }]);
  LocaleSwitcher.displayName = "LocaleSwitcher";
  return LocaleSwitcher;
}(_react.Component);

exports.default = LocaleSwitcher;
LocaleSwitcher.propTypes = {
  children: _propTypes.default.node.isRequired
};