"use strict";var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=exports.I18nLoader=void 0;var _regenerator=_interopRequireDefault(require("@babel/runtime/regenerator")),_objectSpread3=_interopRequireDefault(require("@babel/runtime/helpers/objectSpread")),_asyncToGenerator2=_interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator")),_classCallCheck2=_interopRequireDefault(require("@babel/runtime/helpers/classCallCheck")),_createClass2=_interopRequireDefault(require("@babel/runtime/helpers/createClass")),_possibleConstructorReturn2=_interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn")),_getPrototypeOf3=_interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf")),_inherits2=_interopRequireDefault(require("@babel/runtime/helpers/inherits")),_assertThisInitialized2=_interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized")),_defineProperty2=_interopRequireDefault(require("@babel/runtime/helpers/defineProperty")),_react=_interopRequireDefault(require("react")),_propTypes=_interopRequireDefault(require("prop-types")),_react2=require("@lingui/react"),I18nLoader=/*#__PURE__*/function(_React$Component){function I18nLoader(){var _getPrototypeOf2,_this;(0,_classCallCheck2.default)(this,I18nLoader);for(var _len=arguments.length,args=Array(_len),_key=0;_key<_len;_key++)args[_key]=arguments[_key];return _this=(0,_possibleConstructorReturn2.default)(this,(_getPrototypeOf2=(0,_getPrototypeOf3.default)(I18nLoader)).call.apply(_getPrototypeOf2,[this].concat(args))),(0,_defineProperty2.default)((0,_assertThisInitialized2.default)((0,_assertThisInitialized2.default)(_this)),"state",{catalogs:{}}),(0,_defineProperty2.default)((0,_assertThisInitialized2.default)((0,_assertThisInitialized2.default)(_this)),"loadCatalog",/*#__PURE__*/function(){var _ref=(0,_asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee(language){var catalog;return _regenerator.default.wrap(function(_context){for(;;)switch(_context.prev=_context.next){case 0:return _context.next=2,import(/* webpackMode: "lazy", webpackChunkName: "i18n-[index]" */"@kudoo/locale/".concat(language,"/messages.js"));case 2:catalog=_context.sent,_this.setState(function(state){return{catalogs:(0,_objectSpread3.default)({},state.catalogs,(0,_defineProperty2.default)({},language,catalog))}});case 4:case"end":return _context.stop();}},_callee,this)}));return function(){return _ref.apply(this,arguments)}}()),_this}return(0,_inherits2.default)(I18nLoader,_React$Component),(0,_createClass2.default)(I18nLoader,[{key:"componentDidMount",value:function componentDidMount(){this.loadCatalog(this.props.language)}},{key:"shouldComponentUpdate",value:function shouldComponentUpdate(nextProps,nextState){var language=nextProps.language,catalogs=nextState.catalogs;return!!(language===this.props.language||catalogs[language])||(this.loadCatalog(language),!1)}},{key:"render",value:function render(){var _this$props=this.props,children=_this$props.children,language=_this$props.language,catalogs=this.state.catalogs;// Skip rendering when catalog isn't loaded.
return catalogs[language]?_react.default.createElement(_react2.I18nProvider,{language:language,catalogs:catalogs,missing:"\uD83D\uDEA8"},children):null}}]),I18nLoader}(_react.default.Component);exports.I18nLoader=I18nLoader,(0,_defineProperty2.default)(I18nLoader,"propTypes",{language:_propTypes.default.string,children:_propTypes.default.node}),(0,_defineProperty2.default)(I18nLoader,"defaultProps",{language:"en_AU"});var _default=I18nLoader;exports.default=_default;