import _classCallCheck from"babel-runtime/helpers/classCallCheck";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 classnames from"classnames";import{getMonthName,getTodayTime}from"../util/index";var ROW=4,COL=3;function chooseMonth(e){var t=this.state.value.clone();t.month(e),this.setAndSelectValue(t)}function noop(){}var MonthTable=function(e){function t(o){_classCallCheck(this,t);var l=_possibleConstructorReturn(this,e.call(this,o));return l.state={value:o.value},l}return _inherits(t,e),t.prototype.componentWillReceiveProps=function(e){"value"in e&&this.setState({value:e.value})},t.prototype.setAndSelectValue=function(e){this.setState({value:e}),this.props.onSelect(e)},t.prototype.months=function(){for(var e=this.state.value.clone(),t=[],o=0,l=0;l<ROW;l++){t[l]=[];for(var a=0;a<COL;a++){e.month(o);var r=getMonthName(e);t[l][a]={value:o,content:r,title:r},o++}}return t},t.prototype.render=function(){var e=this,t=this.props,o=this.state.value,l=getTodayTime(o),a=this.months(),r=o.month(),n=t.prefixCls,s=t.locale,c=t.contentRender,i=t.cellRender,p=a.map(function(a,p){var u=a.map(function(a){var p=void 0,u=!1;if(t.disabledDate){var m=o.clone();m.month(a.value),u=t.disabledDate(m)}var h=((p={})[n+"-cell"]=1,p[n+"-cell-disabled"]=u,p[n+"-selected-cell"]=a.value===r,p[n+"-current-cell"]=l.year()===o.year()&&a.value===l.month(),p),v=void 0;if(i){var f=o.clone();f.month(a.value),v=i(f,s)}else{var d=void 0;if(c){var b=o.clone();b.month(a.value),d=c(b,s)}else d=a.content;v=React.createElement("a",{className:n+"-month"},d)}return React.createElement("td",{role:"gridcell",key:a.value,onClick:u?null:chooseMonth.bind(e,a.value),title:a.title,className:classnames(h)},v)});return React.createElement("tr",{key:p,role:"row"},u)});return React.createElement("table",{className:n+"-table",cellSpacing:"0",role:"grid"},React.createElement("tbody",{className:n+"-tbody"},p))},t}(React.Component);MonthTable.defaultProps={onSelect:noop},MonthTable.propTypes={onSelect:PropTypes.func,cellRender:PropTypes.func,prefixCls:PropTypes.string,value:PropTypes.object};export default MonthTable;