import _typeof from"babel-runtime/helpers/typeof";import _defineProperty from"babel-runtime/helpers/defineProperty";import _extends from"babel-runtime/helpers/extends";import _classCallCheck from"babel-runtime/helpers/classCallCheck";import _createClass from"babel-runtime/helpers/createClass";import _possibleConstructorReturn from"babel-runtime/helpers/possibleConstructorReturn";import _inherits from"babel-runtime/helpers/inherits";import*as React from"react";import{Option,OptGroup}from"rc-select";import classNames from"classnames";import Select from"../select";import Input from"../input";import InputElement from"./InputElement";function isSelectOptionOrSelectOptGroup(e){return e&&e.type&&(e.type.isSelectOption||e.type.isSelectOptGroup)}var AutoComplete=function(e){function t(){_classCallCheck(this,t);var e=_possibleConstructorReturn(this,(t.__proto__||Object.getPrototypeOf(t)).apply(this,arguments));return e.getInputElement=function(){var t=e.props.children,r=t&&React.isValidElement(t)&&t.type!==Option?React.Children.only(e.props.children):React.createElement(Input,null),o=_extends({},r.props);return delete o.children,React.createElement(InputElement,o,r)},e.saveSelect=function(t){e.select=t},e}return _inherits(t,e),_createClass(t,[{key:"focus",value:function(){this.select.focus()}},{key:"blur",value:function(){this.select.blur()}},{key:"render",value:function(){var e,t=this.props,r=t.size,o=t.className,n=void 0===o?"":o,l=t.notFoundContent,p=t.prefixCls,i=t.optionLabelProp,s=t.dataSource,a=t.children,c=classNames((_defineProperty(e={},p+"-lg","large"===r),_defineProperty(e,p+"-sm","small"===r),_defineProperty(e,n,!!n),_defineProperty(e,p+"-show-search",!0),_defineProperty(e,p+"-auto-complete",!0),e)),u=void 0,m=React.Children.toArray(a);return u=m.length&&isSelectOptionOrSelectOptGroup(m[0])?a:s?s.map(function(e){if(React.isValidElement(e))return e;switch(void 0===e?"undefined":_typeof(e)){case"string":return React.createElement(Option,{key:e},e);case"object":return React.createElement(Option,{key:e.value},e.text);default:throw new Error("AutoComplete[dataSource] only supports type `string[] | Object[]`.")}}):[],React.createElement(Select,_extends({},this.props,{className:c,mode:"combobox",optionLabelProp:i,getInputElement:this.getInputElement,notFoundContent:l,ref:this.saveSelect}),u)}}]),t}(React.Component);export default AutoComplete;AutoComplete.Option=Option,AutoComplete.OptGroup=OptGroup,AutoComplete.defaultProps={prefixCls:"dt-select",transitionName:"slide-up",optionLabelProp:"children",choiceTransitionName:"zoom",showSearch:!1,filterOption:!1};