'use strict';

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

var _class, _temp2;

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

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

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

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

var _propTypes2 = _interopRequireDefault(_propTypes);

var _lodash = require('lodash');

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

const { config, i18n } = window;
const __ = i18n.setting.__.bind(i18n.setting);

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

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

    return _temp = super(...args), this.state = {
      zoomLevel: config.get('poi.zoomLevel', 1)
    }, this.handleChangeZoomLevel = e => {
      config.set('poi.zoomLevel', this.state.zoomLevel);
    }, this.componentWillReceiveProps = nextProps => {
      if (this.state.zoomLevel !== nextProps.zoomLevel) {
        this.setState({
          zoomLevel: nextProps.zoomLevel
        });
      }
    }, _temp;
  }

  render() {
    return _react2.default.createElement(
      _reactBootstrap.Grid,
      null,
      _react2.default.createElement(
        _reactBootstrap.Col,
        { xs: 6 },
        _react2.default.createElement(
          _reactBootstrap.OverlayTrigger,
          { placement: 'top', overlay: _react2.default.createElement(
              _reactBootstrap.Tooltip,
              { id: 'displayconfig-zoom' },
              __('Zoom level'),
              ' ',
              _react2.default.createElement(
                'strong',
                null,
                parseInt(this.state.zoomLevel * 100),
                '%'
              )
            ) },
          _react2.default.createElement(_reactBootstrap.FormControl, { type: 'range', onInput: e => this.setState({ zoomLevel: parseFloat(e.target.value) }),
            min: 0.5, max: 4.0, step: 0.05, defaultValue: this.state.zoomLevel,
            onMouseUp: this.handleChangeZoomLevel,
            onTouchEnd: this.handleChangeZoomLevel })
        )
      ),
      _react2.default.createElement(
        _reactBootstrap.Col,
        { xs: 6 },
        __('Zoom level'),
        ' ',
        _react2.default.createElement(
          'strong',
          null,
          parseInt(this.state.zoomLevel * 100),
          '%'
        )
      )
    );
  }
}, _class.propTypes = {
  zoomLevel: _propTypes2.default.number
}, _temp2));

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