'use strict';

Object.defineProperty(exports, "__esModule", {
  value: true
});

var _class, _temp2;

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

var _propTypes = require('prop-types');

var _propTypes2 = _interopRequireDefault(_propTypes);

var _reactRedux = require('react-redux');

var _lodash = require('lodash');

var _reactBootstrap = require('react-bootstrap');

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

const { config } = window;

let language = window.language;
if (!['zh-CN', 'zh-TW', 'ja-JP', 'en-US', 'ko-KR'].includes(language)) {
  switch (language.substr(0, 1).toLowerCase()) {
    case 'zh':
      language = 'zh-TW';
      break;
    case 'ja':
      language = 'ja-JP';
      break;
    case 'ko':
      language = 'ko-KR';
      break;
    default:
      language = 'en-US';
  }
}

function _ref(state, props) {
  return {
    value: (0, _lodash.get)(state.config, 'poi.language', language)
  };
}

function _ref2(e) {
  const language = e.target.value;
  config.set('poi.language', language);
}

const LanguageConfig = (0, _reactRedux.connect)(() => {
  return _ref;
})((_temp2 = _class = class LanguageConfig extends _react.Component {
  constructor(...args) {
    var _temp;

    return _temp = super(...args), this.handleSetLanguage = _ref2, _temp;
  }

  render() {
    return _react2.default.createElement(
      _reactBootstrap.Grid,
      null,
      _react2.default.createElement(
        _reactBootstrap.Col,
        { xs: 6 },
        _react2.default.createElement(
          _reactBootstrap.FormControl,
          { componentClass: 'select', value: this.props.value, onChange: this.handleSetLanguage },
          _react2.default.createElement(
            'option',
            { value: 'zh-CN' },
            '\u7B80\u4F53\u4E2D\u6587'
          ),
          _react2.default.createElement(
            'option',
            { value: 'zh-TW' },
            '\u6B63\u9AD4\u4E2D\u6587'
          ),
          _react2.default.createElement(
            'option',
            { value: 'ja-JP' },
            '\u65E5\u672C\u8A9E'
          ),
          _react2.default.createElement(
            'option',
            { value: 'en-US' },
            'English'
          ),
          _react2.default.createElement(
            'option',
            { value: 'ko-KR' },
            '\uD55C\uAD6D\uC5B4'
          )
        )
      )
    );
  }
}, _class.propTypes = {
  value: _propTypes2.default.string
}, _temp2));

exports.default = LanguageConfig;
module.exports = exports['default'];