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*as PropTypes from"prop-types";import Select from"./Select";var formatOption=function(e,t){var o=""+e;e<10&&(o="0"+e);var r=!1;return t&&t.indexOf(e)>=0&&(r=!0),{value:o,disabled:r}},Combobox=function(e){function t(){_classCallCheck(this,t);var e=_possibleConstructorReturn(this,(t.__proto__||Object.getPrototypeOf(t)).apply(this,arguments));return e.onItemChange=function(t,o){var r=e.props,n=r.onChange,s=r.defaultOpenValue,p=r.use12Hours,i=(e.props.value||s).clone();if("hour"===t)p?e.props.isAM?i.hour(+o%12):i.hour(+o%12+12):i.hour(+o);else if("minute"===t)i.minute(+o);else if("ampm"===t){var u=o.toUpperCase();p&&("PM"===u&&i.hour()<12&&i.hour(i.hour()%12+12),"AM"===u&&i.hour()>=12&&i.hour(i.hour()-12))}else i.second(+o);n(i)},e.onEnterSelectPanel=function(t){e.props.onCurrentSelectPanelChange(t)},e}return _inherits(t,e),_createClass(t,[{key:"getHourSelect",value:function(e){var t=this.props,o=t.prefixCls,r=t.hourOptions,n=t.disabledHours,s=t.showHour,p=t.use12Hours;if(!s)return null;var i=n(),u=void 0,l=void 0;return p?(u=[12].concat(r.filter(function(e){return e<12&&e>0})),l=e%12||12):(u=r,l=e),React.createElement(Select,{prefixCls:o,options:u.map(function(e){return formatOption(e,i)}),selectedIndex:u.indexOf(l),type:"hour",onSelect:this.onItemChange,onMouseEnter:this.onEnterSelectPanel.bind(this,"hour")})}},{key:"getMinuteSelect",value:function(e){var t=this.props,o=t.prefixCls,r=t.minuteOptions,n=t.disabledMinutes,s=t.defaultOpenValue;if(!t.showMinute)return null;var p=n((this.props.value||s).hour());return React.createElement(Select,{prefixCls:o,options:r.map(function(e){return formatOption(e,p)}),selectedIndex:r.indexOf(e),type:"minute",onSelect:this.onItemChange,onMouseEnter:this.onEnterSelectPanel.bind(this,"minute")})}},{key:"getSecondSelect",value:function(e){var t=this.props,o=t.prefixCls,r=t.secondOptions,n=t.disabledSeconds,s=t.showSecond,p=t.defaultOpenValue;if(!s)return null;var i=this.props.value||p,u=n(i.hour(),i.minute());return React.createElement(Select,{prefixCls:o,options:r.map(function(e){return formatOption(e,u)}),selectedIndex:r.indexOf(e),type:"second",onSelect:this.onItemChange,onMouseEnter:this.onEnterSelectPanel.bind(this,"second")})}},{key:"getAMPMSelect",value:function(){var e=this.props,t=e.prefixCls,o=e.use12Hours,r=e.format;if(!o)return null;var n=["am","pm"].map(function(e){return r.match(/\sA/)?e.toUpperCase():e}).map(function(e){return{value:e}}),s=this.props.isAM?0:1;return React.createElement(Select,{prefixCls:t,options:n,selectedIndex:s,type:"ampm",onSelect:this.onItemChange,onMouseEnter:this.onEnterSelectPanel.bind(this,"ampm")})}},{key:"render",value:function(){var e=this.props,t=e.prefixCls,o=e.defaultOpenValue,r=this.props.value||o;return React.createElement("div",{className:t+"-combobox"},this.getHourSelect(r.hour()),this.getMinuteSelect(r.minute()),this.getSecondSelect(r.second()),this.getAMPMSelect())}}]),t}(React.Component);Combobox.propTypes={format:PropTypes.string,defaultOpenValue:PropTypes.object,prefixCls:PropTypes.string,value:PropTypes.object,onChange:PropTypes.func,showHour:PropTypes.bool,showMinute:PropTypes.bool,showSecond:PropTypes.bool,hourOptions:PropTypes.array,minuteOptions:PropTypes.array,secondOptions:PropTypes.array,disabledHours:PropTypes.func,disabledMinutes:PropTypes.func,disabledSeconds:PropTypes.func,onCurrentSelectPanelChange:PropTypes.func,use12Hours:PropTypes.bool,isAM:PropTypes.bool};export default Combobox;