'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 {
    panelMinSize: (0, _lodash.get)(state.config, 'poi.panelMinSize', 1),
    layout: (0, _lodash.get)(state.config, 'poi.layout', 'horizontal')
  };
}

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

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

  render() {
    const configName = this.props.layout == 'horizontal' ? 'Minimal width' : 'Minimal height';
    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-panel-size' },
              __(configName),
              ' ',
              _react2.default.createElement(
                'strong',
                null,
                parseInt(this.state.panelMinSize * 100),
                '%'
              )
            ) },
          _react2.default.createElement(_reactBootstrap.FormControl, { type: 'range', onInput: e => this.setState({ panelMinSize: parseFloat(e.target.value) }),
            min: 1.0, max: 2.0, step: 0.05, defaultValue: this.state.panelMinSize,
            onMouseUp: this.handleChangePanelMinSize,
            onTouchEnd: this.handleChangePanelMinSize })
        )
      ),
      _react2.default.createElement(
        _reactBootstrap.Col,
        { xs: 6 },
        __(configName),
        ' ',
        _react2.default.createElement(
          'strong',
          null,
          parseInt(this.state.panelMinSize * 100),
          '%'
        )
      )
    );
  }
}, _class.propTypes = {
  panelMinSize: _propTypes2.default.number,
  layout: _propTypes2.default.string
}, _temp2));

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