import _extends from"babel-runtime/helpers/extends";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*as moment from"moment";import LocaleReceiver from"../locale-provider/LocaleReceiver";import FullCalendar from"../calendarbase/FullCalendar";import{PREFIX_CLS}from"./Constants";import callMoment from"../_util/callMoment";import defaultLocals from"../locale-provider/default";function noop(){return null}function zerofixed(e){return e<10?"0"+e:""+e}var Calendar=function(e){function t(e){_classCallCheck(this,t);var l=_possibleConstructorReturn(this,(t.__proto__||Object.getPrototypeOf(t)).call(this,e));l.dateCellRender=function(e){var t=l.props,a=t.prefixCls,n=t.dateCellRender,r=void 0===n?noop:n;return React.createElement("div",{className:a+"-date"},React.createElement("div",{className:a+"-value"},zerofixed(e.date())),React.createElement("div",{className:a+"-content"},r(e)))},l.setValue=function(e,t){l.setState({value:e}),"select"===t?l.props.onSelect&&l.props.onSelect(e):"changePanel"===t&&l.onPanelChange(e,l.state.mode)},l.setType=function(e){var t=e;l.state.mode!==t&&(l.setState({mode:t}),l.onPanelChange(l.state.value,t))},l.onHeaderValueChange=function(e){l.setValue(e,"changePanel")},l.onHeaderTypeChange=function(e){l.setType(e)},l.onSelect=function(e){l.setValue(e,"select")},l.renderCalendar=function(e,t){var a=l.state,n=l.props,r=a.value,o=a.mode;r&&t&&r.locale(t);var s=n.prefixCls,c=n.style,p=n.className,u=n.fullscreen,m=n.dateFullCellRender,i=o,d=p||"";u&&(d+=" "+s+"-fullscreen");var f=m||l.dateCellRender;return React.createElement("div",{className:d,style:c},React.createElement(FullCalendar,_extends({},n,{Select:noop,locale:e.lang,type:i,prefixCls:s,value:r,dateCellRender:f,onSelect:l.onSelect,onValueChange:l.onHeaderValueChange,onTypeChange:l.onHeaderTypeChange,fullscreen:u})))};var a=e.value||e.defaultValue||callMoment(moment);if(!moment.isMoment(a))throw new Error("The value/defaultValue of Calendar must be a moment object after `dtd@2.0`, see: #");return l.state={value:a,mode:e.mode},l}return _inherits(t,e),_createClass(t,[{key:"componentWillReceiveProps",value:function(e){"value"in e&&this.setState({value:e.value}),"mode"in e&&e.mode!==this.props.mode&&this.setState({mode:e.mode})}},{key:"onPanelChange",value:function(e,t){var l=this.props.onPanelChange;l&&l(e,t)}},{key:"render",value:function(){return React.createElement(LocaleReceiver,{componentName:"Calendar",defaultLocale:defaultLocals.Calendar},this.renderCalendar)}}]),t}(React.Component);export default Calendar;Calendar.defaultProps={locale:{},fullscreen:!0,prefixCls:PREFIX_CLS,mode:"month",onSelect:noop,onPanelChange:noop},Calendar.propTypes={monthCellRender:PropTypes.func,monthFullCellRender:PropTypes.func,dateCellRender:PropTypes.func,dateFullCellRender:PropTypes.func,fullscreen:PropTypes.bool,locale:PropTypes.object,prefixCls:PropTypes.string,className:PropTypes.string,style:PropTypes.object,onPanelChange:PropTypes.func,value:PropTypes.object,onSelect:PropTypes.func};