import*as React from"react";import createReactClass from"create-react-class";import*as PropTypes from"prop-types";import DateTable from"./date/DateTable";import WeekTable from"./week/WeekTable";import CalendarMixin from"./mixin/CalendarMixin";import CommonMixin from"./mixin/CommonMixin";import moment from"moment";import cx from"classnames";var FullCalendar=createReactClass({displayName:"FullCalendar",propTypes:{defaultType:PropTypes.string,type:PropTypes.string,prefixCls:PropTypes.string,locale:PropTypes.object,onTypeChange:PropTypes.func,fullscreen:PropTypes.bool,monthCellRender:PropTypes.func,showTypeSwitch:PropTypes.bool,Select:PropTypes.func.isRequired,disabledDate:PropTypes.func,weekTimes:PropTypes.array},mixins:[CommonMixin,CalendarMixin],getDefaultProps:function(){return{fullscreen:!1,showTypeSwitch:!0,onTypeChange:function(){}}},getInitialState:function(){return{type:this.props.type||"month"}},componentWillReceiveProps:function(e){"type"in e&&this.setState({type:e.type})},setType:function(e){this.weekTimes=[],"type"in this.props||this.setState({type:e}),this.props.onTypeChange(e)},goTargetDate:function(e){this.weekTimes=[];var t=this.props.value.clone(),a="month"===this.state.type?"months":"week"===this.state.type?"week":"day";t.add(e,a),this.props.onValueChange(t)},goToday:function(){var e=moment();this.props.onValueChange(e)},weekTimes:[],onChangeWeek:function(e){this.weekTimes.push(e.clone())},changeMonthElement:function(){var e=this.props,t=e.value,a=e.prefixCls,n=e.locale;return React.createElement("div",{style:{display:"inline-block"}},React.createElement("a",{key:"prev-month",className:a+"-prev-month",title:n.previousMonth,onClick:this.goTargetDate.bind(this,-1)}),React.createElement("a",{key:"today",className:cx(a+"-today",t.year()===moment().year()&&t.month()===moment().month()&&t.date()===moment().date()?null:a+"-go-today"),onClick:this.goToday},"今天"),React.createElement("a",{key:"next-month",className:a+"-next-month",title:n.nextMonth,onClick:this.goTargetDate.bind(this,1)}))},changePanelElement:function(){var e=this.state,t=this.props.prefixCls,a=t+"-panel-btn";return React.createElement("div",{style:{display:"inline-block"}},React.createElement("a",{key:"day",className:cx(a,"day"===e.type?t+"-select-panel":null),onClick:this.setType.bind(this,"day")},"日"),React.createElement("a",{key:"week",className:cx(a,"week"===e.type?t+"-select-panel":null),onClick:this.setType.bind(this,"week")},"周"),React.createElement("a",{key:"month",className:cx(a,"month"===e.type?t+"-select-panel":null),onClick:this.setType.bind(this,"month")},"月"))},render:function(){var e=this.props,t=e.locale,a=e.prefixCls,n=e.fullscreen,l=e.disabledDate,s=e.value,o=this.state.type,i="month"===o?React.createElement(DateTable,{dateRender:e.dateCellRender,contentRender:e.dateCellContentRender,locale:t,prefixCls:a,onSelect:this.onSelect,value:s,disabledDate:l}):React.createElement(WeekTable,{locale:t,prefixCls:a,onChangeWeek:this.onChangeWeek,value:s,onSelectTime:this.props.onSelectTime,weekTimes:this.weekTimes,disabledDate:l,isDay:"day"===o}),r=React.createElement("div",{key:"calendar-header",className:a+"-header"},React.createElement("div",{key:"calendar-current-date",className:a+"-current-date"},s.year()+"年"+(s.month()+1)+"月"),n&&React.createElement("div",{key:"calendar-filter-date",className:a+"-filter-date"},this.changeMonthElement(),this.changePanelElement())),c=React.createElement("div",{key:"calendar-body",className:a+"-calendar-body"},i),p=[a+"-full"];return n&&p.push(a+"-fullscreen"),this.renderRoot({children:[r,c],className:p.join(" ")})}});export default FullCalendar;