import*as React from"react";import*as PropTypes from"prop-types";import classnames from"classnames";import moment from"moment";import{getTodayTime,isAllowedDate as _isAllowedDate}from"../util/index";function noop(){}function getNow(){return moment()}function getNowByCurrentStateValue(e){return e?getTodayTime(e):getNow()}var CalendarMixin={propTypes:{value:PropTypes.object,defaultValue:PropTypes.object,onKeyDown:PropTypes.func},getDefaultProps:function(){return{onKeyDown:noop}},getInitialState:function(){var e=this.props;return{value:e.value||e.defaultValue||getNow(),selectedValue:e.selectedValue||e.defaultSelectedValue}},componentWillReceiveProps:function(e){var t=e.value,a=e.selectedValue;"value"in e&&(t=t||e.defaultValue||getNowByCurrentStateValue(this.state.value),this.setState({value:t})),"selectedValue"in e&&this.setState({selectedValue:a})},onSelect:function(e,t){e&&this.setValue(e),this.setSelectedValue(e,t)},renderRoot:function(e){var t=void 0,a=this.props,s=a.prefixCls,o=((t={})[s]=1,t[s+"-hidden"]=!a.visible,t[a.className]=!!a.className,t[e.className]=!!e.className,t);return React.createElement("div",{ref:this.saveRoot,className:""+classnames(o),style:this.props.style,tabIndex:"0",onKeyDown:this.onKeyDown},e.children)},setSelectedValue:function(e,t){"selectedValue"in this.props||this.setState({selectedValue:e}),this.props.onSelect(e,t)},setValue:function(e){var t=this.state.value;"value"in this.props||this.setState({value:e}),(t&&e&&!t.isSame(e)||!t&&e||t&&!e)&&this.props.onChange(e)},isAllowedDate:function(e){var t=this.props.disabledDate,a=this.props.disabledTime;return _isAllowedDate(e,t,a)}};export default CalendarMixin;