"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var _defineProperty2=require("babel-runtime/helpers/defineProperty"),_defineProperty3=_interopRequireDefault(_defineProperty2),_classCallCheck2=require("babel-runtime/helpers/classCallCheck"),_classCallCheck3=_interopRequireDefault(_classCallCheck2),_createClass2=require("babel-runtime/helpers/createClass"),_createClass3=_interopRequireDefault(_createClass2),_possibleConstructorReturn2=require("babel-runtime/helpers/possibleConstructorReturn"),_possibleConstructorReturn3=_interopRequireDefault(_possibleConstructorReturn2),_inherits2=require("babel-runtime/helpers/inherits"),_inherits3=_interopRequireDefault(_inherits2),_react=require("react"),React=_interopRequireWildcard(_react),_propTypes=require("prop-types"),PropTypes=_interopRequireWildcard(_propTypes),_reactDom=require("react-dom"),ReactDom=_interopRequireWildcard(_reactDom),_classnames3=require("classnames"),_classnames4=_interopRequireDefault(_classnames3);function _interopRequireWildcard(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r]);return t.default=e,t}function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}var scrollTo=function e(t,r,s){var o=window.requestAnimationFrame||function(e){return setTimeout(e,10)};if(s<=0)t.scrollTop=r;else{var l=(r-t.scrollTop)/s*10;o(function(){t.scrollTop=t.scrollTop+l,t.scrollTop!==r&&e(t,r,s-10)})}},Select=function(e){function t(){(0,_classCallCheck3.default)(this,t);var r=(0,_possibleConstructorReturn3.default)(this,(t.__proto__||Object.getPrototypeOf(t)).apply(this,arguments));return r.state={active:!1},r.onSelect=function(e){var t=r.props;(0,t.onSelect)(t.type,e)},r.handleMouseEnter=function(e){r.setState({active:!0}),r.props.onMouseEnter(e)},r.handleMouseLeave=function(){r.setState({active:!1})},r.saveList=function(e){r.list=e},r}return(0,_inherits3.default)(t,e),(0,_createClass3.default)(t,[{key:"componentDidMount",value:function(){this.scrollToSelected(0)}},{key:"componentDidUpdate",value:function(e){e.selectedIndex!==this.props.selectedIndex&&this.scrollToSelected(120)}},{key:"getOptions",value:function(){var l=this,e=this.props,t=e.options,n=e.selectedIndex,i=e.prefixCls;return t.map(function(e,t){var r,s=(0,_classnames4.default)((r={},(0,_defineProperty3.default)(r,i+"-select-option-selected",n===t),(0,_defineProperty3.default)(r,i+"-select-option-disabled",e.disabled),r)),o=null;return e.disabled||(o=l.onSelect.bind(l,e.value)),React.createElement("li",{className:s,key:t,onClick:o},e.value)})}},{key:"scrollToSelected",value:function(e){var t=ReactDom.findDOMNode(this),r=ReactDom.findDOMNode(this.list);if(r){var s=this.props.selectedIndex;s<0&&(s=0);var o=r.children[s].offsetTop;scrollTo(t,o,e)}}},{key:"render",value:function(){var e;if(0===this.props.options.length)return null;var t=this.props.prefixCls,r=(0,_classnames4.default)((e={},(0,_defineProperty3.default)(e,t+"-select",1),(0,_defineProperty3.default)(e,t+"-select-active",this.state.active),e));return React.createElement("div",{className:r,onMouseEnter:this.handleMouseEnter,onMouseLeave:this.handleMouseLeave},React.createElement("ul",{ref:this.saveList},this.getOptions()))}}]),t}(React.Component);Select.propTypes={prefixCls:PropTypes.string,options:PropTypes.array,selectedIndex:PropTypes.number,type:PropTypes.string,onSelect:PropTypes.func,onMouseEnter:PropTypes.func},exports.default=Select,module.exports=exports.default;