"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")),_interopRequireWildcard2=_interopRequireDefault(require("@babel/runtime/helpers/interopRequireWildcard")),_asyncToGenerator2=_interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator")),_classCallCheck2=_interopRequireDefault(require("@babel/runtime/helpers/classCallCheck")),_createClass2=_interopRequireDefault(require("@babel/runtime/helpers/createClass")),_assertThisInitialized2=_interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized")),_inherits2=_interopRequireDefault(require("@babel/runtime/helpers/inherits")),_possibleConstructorReturn2=_interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn")),_getPrototypeOf2=_interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf")),_defineProperty2=_interopRequireDefault(require("@babel/runtime/helpers/defineProperty")),_react=_interopRequireDefault(require("react")),_propTypes=_interopRequireDefault(require("prop-types")),_react2=require("@lingui/react");function ownKeys(object,enumerableOnly){var keys=Object.keys(object);if(Object.getOwnPropertySymbols){var symbols=Object.getOwnPropertySymbols(object);enumerableOnly&&(symbols=symbols.filter(function(sym){return Object.getOwnPropertyDescriptor(object,sym).enumerable})),keys.push.apply(keys,symbols)}return keys}function _objectSpread(target){for(var source,i=1;i<arguments.length;i++)source=null==arguments[i]?{}:arguments[i],i%2?ownKeys(Object(source),!0).forEach(function(key){(0,_defineProperty2["default"])(target,key,source[key])}):Object.getOwnPropertyDescriptors?Object.defineProperties(target,Object.getOwnPropertyDescriptors(source)):ownKeys(Object(source)).forEach(function(key){Object.defineProperty(target,key,Object.getOwnPropertyDescriptor(source,key))});return target}function _createSuper(Derived){var hasNativeReflectConstruct=_isNativeReflectConstruct();return function(){var result,Super=(0,_getPrototypeOf2["default"])(Derived);if(hasNativeReflectConstruct){var NewTarget=(0,_getPrototypeOf2["default"])(this).constructor;result=Reflect.construct(Super,arguments,NewTarget)}else result=Super.apply(this,arguments);return(0,_possibleConstructorReturn2["default"])(this,result)}}function _isNativeReflectConstruct(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],function(){})),!0}catch(e){return!1}}var I18nLoader=/*#__PURE__*/function(_React$Component){function I18nLoader(){var _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=_super.call.apply(_super,[this].concat(args)),(0,_defineProperty2["default"])((0,_assertThisInitialized2["default"])(_this),"state",{catalogs:{}}),(0,_defineProperty2["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,Promise.resolve("@kudoo/locale/".concat(language,"/messages.js")).then(function(s){return(0,_interopRequireWildcard2["default"])(require(s))});case 2:catalog=_context.sent,_this.setState(function(state){return{catalogs:_objectSpread(_objectSpread({},state.catalogs),{},(0,_defineProperty2["default"])({},language,catalog))}});case 4:case"end":return _context.stop();}},_callee)}));return function(){return _ref.apply(this,arguments)}}()),_this}(0,_inherits2["default"])(I18nLoader,_React$Component);var _super=_createSuper(I18nLoader);return(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]?/*#__PURE__*/_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;