'use strict';

exports.__esModule = true;
exports.default = undefined;

var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };

var _class, _temp;

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

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

var _propTypes2 = _interopRequireDefault(_propTypes);

var _InputText = require('./../InputText');

var _InputText2 = _interopRequireDefault(_InputText);

var _PickerCity = require('./../PickerCity');

var _PickerCity2 = _interopRequireDefault(_PickerCity);

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

function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; }

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }

function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }

var InputCity = (_temp = _class = function (_Component) {
  _inherits(InputCity, _Component);

  function InputCity(props) {
    _classCallCheck(this, InputCity);

    var _this = _possibleConstructorReturn(this, _Component.call(this, props));

    _this.onClickInput = function () {
      var onClick = _this.props.onClick;

      if (onClick) onClick.apply(undefined, arguments);
      _this.setState(function (prevState) {
        return {
          show: !prevState.show
        };
      });
    };

    _this.onClickMask = function (e) {
      var _this$props$pickerPro = _this.props.pickerProps,
          pickerProps = _this$props$pickerPro === undefined ? {} : _this$props$pickerPro;

      if (pickerProps && pickerProps.maskAttribute && pickerProps.maskAttribute.onClick) {
        e.target = _this.$input;
        pickerProps.maskAttribute.onClick(e);
        return;
      }
      _this.setState(function (prevState) {
        return {
          show: !prevState.show
        };
      });
    };

    _this.onClickSubmit = function (e) {
      var _this$props = _this.props,
          onChange = _this$props.onChange,
          _this$props$pickerPro2 = _this$props.pickerProps,
          pickerProps = _this$props$pickerPro2 === undefined ? {} : _this$props$pickerPro2;
      // 获取值

      if (!_this.$input) _this.$input = _this.refs.$ComponentInputText.$input;
      var value = e.activeText;
      var options = e.activeOptions;
      // 确定按钮回调
      if (pickerProps && pickerProps.submitAttribute && pickerProps.submitAttribute.onClick) {
        e.target = _this.$input;
        pickerProps.submitAttribute.onClick(e, value, options);
        return;
      }
      // 赋值
      if (onChange) {
        e.target = _this.$input;
        onChange(e, value, options);
      }
      // 隐藏框
      _this.setState(function (prevState) {
        return {
          show: !prevState.show
        };
      });
    };

    _this.onClickCancel = function (e) {
      var _this$props$pickerPro3 = _this.props.pickerProps,
          pickerProps = _this$props$pickerPro3 === undefined ? {} : _this$props$pickerPro3;

      if (pickerProps && pickerProps.cancelAttribute && pickerProps.cancelAttribute.onClick) {
        e.target = _this.$input;
        pickerProps.cancelAttribute.onClick(e);
        return;
      }
      _this.setState(function (prevState) {
        return {
          show: !prevState.show
        };
      });
    };

    _this.state = {
      show: false
    };
    return _this;
  }

  InputCity.prototype.componentDidMount = function componentDidMount() {
    this.$el = null;
    this.$input = null;
    if (this.refs.$ComponentInputText && this.refs.$ComponentInputText.$el && this.refs.$ComponentInputText.$input) {
      this.$el = this.refs.$ComponentInputText.$el;
      this.$input = this.refs.$ComponentInputText.$input;
      this.$ComponentInputText = this.refs.$ComponentInputText;
    }
    this.$picker = this.refs.$ComponentPicker;
  };
  // 点击文本框

  // 点击遮罩

  // 点击确定按钮

  // 点击取消按钮


  InputCity.prototype.render = function render() {
    var _props = this.props,
        onClick = _props.onClick,
        onChange = _props.onChange,
        valueForKey = _props.valueForKey,
        type = _props.type,
        _props$pickerProps = _props.pickerProps,
        pickerProps = _props$pickerProps === undefined ? {} : _props$pickerProps,
        others = _objectWithoutProperties(_props, ['onClick', 'onChange', 'valueForKey', 'type', 'pickerProps']);

    return [_react2.default.createElement(_InputText2.default, _extends({ key: 'input', ref: '$ComponentInputText' }, others, { type: 'text', readOnly: true, onClick: this.onClickInput })), _react2.default.createElement(_PickerCity2.default, _extends({
      key: 'pickercity',
      ref: '$ComponentPicker'
    }, pickerProps, {
      maskAttribute: _extends({}, pickerProps.maskAttribute, {
        onClick: this.onClickMask
      }),
      submitAttribute: _extends({}, pickerProps.submitAttribute, {
        onClick: this.onClickSubmit
      }),
      cancelAttribute: _extends({}, pickerProps.cancelAttribute, {
        onClick: this.onClickCancel
      }),
      valueForKey: valueForKey,
      type: type,
      value: this.$input ? this.$input.value : this.props.value,
      show: pickerProps.show === undefined ? this.state.show : pickerProps.show
    }))];
  };

  return InputCity;
}(_react.Component), _class.defaultProps = {
  type: 'district'
}, _class.defaultProps = {}, _temp);
exports.default = InputCity;
InputCity.propTypes = process.env.NODE_ENV !== "production" ? {
  // Input
  onClick: _propTypes2.default.func,
  onChange: _propTypes2.default.func,

  // Picker
  valueForKey: _propTypes2.default.string,
  type: _propTypes2.default.string, // 'district' | 'city'
  pickerProps: _propTypes2.default.object
} : {};
module.exports = exports['default'];