import _defineProperty from"babel-runtime/helpers/defineProperty";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 Header from"./Header";import Combobox from"./Combobox";import moment from"moment";import classNames from"classnames";function noop(){}function generateOptions(e,o,n){for(var r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:1,s=[],t=0;t<e;t+=r)(!o||o.indexOf(t)<0||!n)&&s.push(t);return s}var Panel=function(e){function o(e){_classCallCheck(this,o);var n=_possibleConstructorReturn(this,(o.__proto__||Object.getPrototypeOf(o)).call(this,e));return n.onChange=function(e){n.setState({value:e}),n.props.onChange(e)},n.onCurrentSelectPanelChange=function(e){n.setState({currentSelectPanel:e})},n.disabledHours=function(){var e=n.props,o=e.use12Hours,r=(0,e.disabledHours)();return o&&Array.isArray(r)&&(r=n.isAM()?r.filter(function(e){return e<12}).map(function(e){return 0===e?12:e}):r.map(function(e){return 12===e?12:e-12})),r},n.state={value:e.value,selectionRange:[]},n}return _inherits(o,e),_createClass(o,[{key:"componentWillReceiveProps",value:function(e){var o=e.value;o&&this.setState({value:o})}},{key:"close",value:function(){this.props.onEsc()}},{key:"isAM",value:function(){var e=this.state.value||this.props.defaultOpenValue;return e.hour()>=0&&e.hour()<12}},{key:"render",value:function(){var e,o=this.props,n=o.prefixCls,r=o.className,s=o.placeholder,t=o.disabledMinutes,a=o.disabledSeconds,p=o.hideDisabledOptions,l=o.allowEmpty,i=o.showHour,u=o.showMinute,c=o.showSecond,d=o.format,m=o.defaultOpenValue,h=o.clearText,f=o.onEsc,b=o.addon,y=o.use12Hours,P=o.onClear,C=o.focusOnOpen,O=o.onKeyDown,T=o.hourStep,v=o.minuteStep,g=o.secondStep,S=o.inputReadOnly,H=this.state,w=H.value,_=H.currentSelectPanel,R=this.disabledHours(),x=t(w?w.hour():null),M=a(w?w.hour():null,w?w.minute():null),E=generateOptions(24,R,p,T),k=generateOptions(60,x,p,v),A=generateOptions(60,M,p,g);return React.createElement("div",{className:classNames((e={},_defineProperty(e,n+"-inner",!0),_defineProperty(e,""+r,!!r),e))},React.createElement(Header,{clearText:h,prefixCls:n,defaultOpenValue:m,value:w,currentSelectPanel:_,onEsc:f,format:d,placeholder:s,hourOptions:E,minuteOptions:k,secondOptions:A,disabledHours:this.disabledHours,disabledMinutes:t,disabledSeconds:a,onChange:this.onChange,onClear:P,allowEmpty:l,focusOnOpen:C,onKeyDown:O,inputReadOnly:S}),React.createElement(Combobox,{prefixCls:n,value:w,defaultOpenValue:m,format:d,onChange:this.onChange,showHour:i,showMinute:u,showSecond:c,hourOptions:E,minuteOptions:k,secondOptions:A,disabledHours:this.disabledHours,disabledMinutes:t,disabledSeconds:a,onCurrentSelectPanelChange:this.onCurrentSelectPanelChange,use12Hours:y,isAM:this.isAM()}),b(this))}}]),o}(React.Component);Panel.propTypes={clearText:PropTypes.string,prefixCls:PropTypes.string,className:PropTypes.string,defaultOpenValue:PropTypes.object,value:PropTypes.object,placeholder:PropTypes.string,format:PropTypes.string,inputReadOnly:PropTypes.bool,disabledHours:PropTypes.func,disabledMinutes:PropTypes.func,disabledSeconds:PropTypes.func,hideDisabledOptions:PropTypes.bool,onChange:PropTypes.func,onEsc:PropTypes.func,allowEmpty:PropTypes.bool,showHour:PropTypes.bool,showMinute:PropTypes.bool,showSecond:PropTypes.bool,onClear:PropTypes.func,use12Hours:PropTypes.bool,hourStep:PropTypes.number,minuteStep:PropTypes.number,secondStep:PropTypes.number,addon:PropTypes.func,focusOnOpen:PropTypes.bool,onKeyDown:PropTypes.func},Panel.defaultProps={prefixCls:"rc-time-picker-panel",onChange:noop,onClear:noop,disabledHours:noop,disabledMinutes:noop,disabledSeconds:noop,defaultOpenValue:moment(),use12Hours:!1,addon:noop,onKeyDown:noop,inputReadOnly:!1};export default Panel;