'use strict';

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports['default'] = undefined;

var _icon = require('choerodon-hap-ui/lib/icon');

var _icon2 = _interopRequireDefault(_icon);

var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck');

var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);

var _createClass2 = require('babel-runtime/helpers/createClass');

var _createClass3 = _interopRequireDefault(_createClass2);

var _possibleConstructorReturn2 = require('babel-runtime/helpers/possibleConstructorReturn');

var _possibleConstructorReturn3 = _interopRequireDefault(_possibleConstructorReturn2);

var _inherits2 = require('babel-runtime/helpers/inherits');

var _inherits3 = _interopRequireDefault(_inherits2);

var _select = require('choerodon-hap-ui/lib/select');

var _select2 = _interopRequireDefault(_select);

var _dec, _class, _desc, _value, _class2, _descriptor;

require('choerodon-hap-ui/lib/icon/style');

require('choerodon-hap-ui/lib/select/style');

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

var _mobx = require('mobx');

var _mobxReact = require('mobx-react');

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

function _initDefineProp(target, property, descriptor, context) {
  if (!descriptor) return;
  Object.defineProperty(target, property, {
    enumerable: descriptor.enumerable,
    configurable: descriptor.configurable,
    writable: descriptor.writable,
    value: descriptor.initializer ? descriptor.initializer.call(context) : void 0
  });
}

function _applyDecoratedDescriptor(target, property, decorators, descriptor, context) {
  var desc = {};
  Object['ke' + 'ys'](descriptor).forEach(function (key) {
    desc[key] = descriptor[key];
  });
  desc.enumerable = !!desc.enumerable;
  desc.configurable = !!desc.configurable;

  if ('value' in desc || desc.initializer) {
    desc.writable = true;
  }

  desc = decorators.slice().reverse().reduce(function (desc, decorator) {
    return decorator(target, property, desc) || desc;
  }, desc);

  if (context && desc.initializer !== void 0) {
    desc.value = desc.initializer ? desc.initializer.call(context) : void 0;
    desc.initializer = undefined;
  }

  if (desc.initializer === void 0) {
    Object['define' + 'Property'](target, property, desc);
    desc = null;
  }

  return desc;
}

function _initializerWarningHelper(descriptor, context) {
  throw new Error('Decorating class property failed. Please ensure that transform-class-properties is enabled.');
}

var Option = _select2['default'].Option;
var SearchInput = (_dec = (0, _mobxReact.inject)('MenuStore'), _dec(_class = (0, _mobxReact.observer)(_class = (_class2 = function (_Component) {
  (0, _inherits3['default'])(SearchInput, _Component);

  function SearchInput(props) {
    (0, _classCallCheck3['default'])(this, SearchInput);

    var _this = (0, _possibleConstructorReturn3['default'])(this, (SearchInput.__proto__ || Object.getPrototypeOf(SearchInput)).call(this, props));

    _initDefineProp(_this, 'code', _descriptor, _this);

    _this.handleChange = function (code) {
      _this.setCode(code);
      var onChange = _this.props.onChange;

      onChange(code);
    };

    _this.setCode(null);
    return _this;
  }

  (0, _createClass3['default'])(SearchInput, [{
    key: 'setCode',
    value: function setCode(code) {
      this.code = code;
    }
  }, {
    key: 'render',
    value: function render() {
      var MenuStore = this.props.MenuStore;

      return _react2['default'].createElement(
        'div',
        { className: 'search-input-wrap' },
        _react2['default'].createElement(
          _select2['default'],
          {
            style: { width: 265, borderRadius: 2 },
            placeholder: '\u8F93\u5165\u529F\u80FD\u4EE3\u7801\u6216\u529F\u80FD\u540D\u79F0',
            value: this.code
            // optionFilterProp="children"
            // filterOption={(input, option) => option.props.children.toLowerCase().indexOf(input.toLowerCase()) >= 0}
            // filter
            , onChange: this.handleChange,
            clearButton: false,
            searchable: true
          },
          MenuStore.treeNodeMenus.map(function (node) {
            return _react2['default'].createElement(
              Option,
              {
                key: node.functionCode,
                value: node.functionCode
              },
              node.text
            );
          })
        ),
        _react2['default'].createElement(_icon2['default'], { type: 'search' })
      );
    }
  }]);
  return SearchInput;
}(_react.Component), (_descriptor = _applyDecoratedDescriptor(_class2.prototype, 'code', [_mobx.observable], {
  enumerable: true,
  initializer: null
}), _applyDecoratedDescriptor(_class2.prototype, 'setCode', [_mobx.action], Object.getOwnPropertyDescriptor(_class2.prototype, 'setCode'), _class2.prototype)), _class2)) || _class) || _class);
exports['default'] = SearchInput;