"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var _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),_Select=require("./Select"),_Select2=_interopRequireDefault(_Select);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 formatOption=function(e,t){var r=""+e;e<10&&(r="0"+e);var o=!1;return t&&0<=t.indexOf(e)&&(o=!0),{value:r,disabled:o}},Combobox=function(e){function t(){(0,_classCallCheck3.default)(this,t);var l=(0,_possibleConstructorReturn3.default)(this,(t.__proto__||Object.getPrototypeOf(t)).apply(this,arguments));return l.onItemChange=function(e,t){var r=l.props,o=r.onChange,n=r.defaultOpenValue,s=r.use12Hours,u=(l.props.value||n).clone();if("hour"===e)s?l.props.isAM?u.hour(+t%12):u.hour(+t%12+12):u.hour(+t);else if("minute"===e)u.minute(+t);else if("ampm"===e){var i=t.toUpperCase();s&&("PM"===i&&u.hour()<12&&u.hour(u.hour()%12+12),"AM"===i&&12<=u.hour()&&u.hour(u.hour()-12))}else u.second(+t);o(u)},l.onEnterSelectPanel=function(e){l.props.onCurrentSelectPanelChange(e)},l}return(0,_inherits3.default)(t,e),(0,_createClass3.default)(t,[{key:"getHourSelect",value:function(e){var t=this.props,r=t.prefixCls,o=t.hourOptions,n=t.disabledHours,s=t.showHour,u=t.use12Hours;if(!s)return null;var i=n(),l=void 0,a=void 0;return a=u?(l=[12].concat(o.filter(function(e){return e<12&&0<e})),e%12||12):(l=o,e),React.createElement(_Select2.default,{prefixCls:r,options:l.map(function(e){return formatOption(e,i)}),selectedIndex:l.indexOf(a),type:"hour",onSelect:this.onItemChange,onMouseEnter:this.onEnterSelectPanel.bind(this,"hour")})}},{key:"getMinuteSelect",value:function(e){var t=this.props,r=t.prefixCls,o=t.minuteOptions,n=t.disabledMinutes,s=t.defaultOpenValue;if(!t.showMinute)return null;var u=n((this.props.value||s).hour());return React.createElement(_Select2.default,{prefixCls:r,options:o.map(function(e){return formatOption(e,u)}),selectedIndex:o.indexOf(e),type:"minute",onSelect:this.onItemChange,onMouseEnter:this.onEnterSelectPanel.bind(this,"minute")})}},{key:"getSecondSelect",value:function(e){var t=this.props,r=t.prefixCls,o=t.secondOptions,n=t.disabledSeconds,s=t.showSecond,u=t.defaultOpenValue;if(!s)return null;var i=this.props.value||u,l=n(i.hour(),i.minute());return React.createElement(_Select2.default,{prefixCls:r,options:o.map(function(e){return formatOption(e,l)}),selectedIndex:o.indexOf(e),type:"second",onSelect:this.onItemChange,onMouseEnter:this.onEnterSelectPanel.bind(this,"second")})}},{key:"getAMPMSelect",value:function(){var e=this.props,t=e.prefixCls,r=e.use12Hours,o=e.format;if(!r)return null;var n=["am","pm"].map(function(e){return o.match(/\sA/)?e.toUpperCase():e}).map(function(e){return{value:e}}),s=this.props.isAM?0:1;return React.createElement(_Select2.default,{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,r=e.defaultOpenValue,o=this.props.value||r;return React.createElement("div",{className:t+"-combobox"},this.getHourSelect(o.hour()),this.getMinuteSelect(o.minute()),this.getSecondSelect(o.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},exports.default=Combobox,module.exports=exports.default;