import _extends from "@babel/runtime/helpers/extends";
import React from 'react';
import createReactClass from 'create-react-class';
import DateTable from './date/DateTable';
import MonthTable from './month/MonthTable';
import CalendarMixin from './mixin/CalendarMixin';
import CommonMixin from './mixin/CommonMixin';
import CalendarHeader from './full-calendar/CalendarHeader';
var FullCalendar = createReactClass({
  displayName: "FullCalendar",
  mixins: [CommonMixin, CalendarMixin],
  getDefaultProps: function getDefaultProps() {
    return {
      defaultType: 'date',
      fullscreen: false,
      showTypeSwitch: true,
      showHeader: true,
      onTypeChange: function onTypeChange() {}
    };
  },
  getInitialState: function getInitialState() {
    var type;

    if ('type' in this.props) {
      type = this.props.type;
    } else {
      type = this.props.defaultType;
    }

    return {
      type: type
    };
  },
  componentWillReceiveProps: function componentWillReceiveProps(nextProps) {
    if ('type' in nextProps) {
      this.setState({
        type: nextProps.type
      });
    }
  },
  onMonthSelect: function onMonthSelect(value) {
    this.onSelect(value, {
      target: 'month'
    });
  },
  setType: function setType(type) {
    if (!('type' in this.props)) {
      this.setState({
        type: type
      });
    }

    this.props.onTypeChange(type);
  },
  render: function render() {
    var props = this.props;
    var locale = props.locale,
        prefixCls = props.prefixCls,
        fullscreen = props.fullscreen,
        showHeader = props.showHeader,
        headerComponent = props.headerComponent,
        headerRender = props.headerRender,
        disabledDate = props.disabledDate;
    var _this$state = this.state,
        value = _this$state.value,
        type = _this$state.type;
    var header = null;

    if (showHeader) {
      if (headerRender) {
        header = headerRender(value, type, locale);
      } else {
        var TheHeader = headerComponent || CalendarHeader;
        header = /*#__PURE__*/React.createElement(TheHeader, _extends({
          key: "calendar-header"
        }, props, {
          prefixCls: "".concat(prefixCls, "-full"),
          type: type,
          value: value,
          onTypeChange: this.setType,
          onValueChange: this.setValue
        }));
      }
    }

    var table = type === 'date' ? /*#__PURE__*/React.createElement(DateTable, {
      dateRender: props.dateCellRender,
      contentRender: props.dateCellContentRender,
      locale: locale,
      prefixCls: prefixCls,
      onSelect: this.onSelect,
      value: value,
      disabledDate: disabledDate
    }) : /*#__PURE__*/React.createElement(MonthTable, {
      cellRender: props.monthCellRender,
      contentRender: props.monthCellContentRender,
      locale: locale,
      onSelect: this.onMonthSelect,
      prefixCls: "".concat(prefixCls, "-month-panel"),
      value: value,
      disabledDate: disabledDate
    });
    var children = [header, /*#__PURE__*/React.createElement("div", {
      key: "calendar-body",
      className: "".concat(prefixCls, "-calendar-body")
    }, table)];
    var className = ["".concat(prefixCls, "-full")];

    if (fullscreen) {
      className.push("".concat(prefixCls, "-fullscreen"));
    }

    return this.renderRoot({
      children: children,
      className: className.join(' ')
    });
  }
});
export default FullCalendar;
//# sourceMappingURL=FullCalendar.js.map
