"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")["default"];

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = void 0;

var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));

var _react = _interopRequireDefault(require("react"));

var _createReactClass = _interopRequireDefault(require("create-react-class"));

var _DateTable = _interopRequireDefault(require("./date/DateTable"));

var _MonthTable = _interopRequireDefault(require("./month/MonthTable"));

var _CalendarMixin = _interopRequireDefault(require("./mixin/CalendarMixin"));

var _CommonMixin = _interopRequireDefault(require("./mixin/CommonMixin"));

var _CalendarHeader = _interopRequireDefault(require("./full-calendar/CalendarHeader"));

var FullCalendar = (0, _createReactClass["default"])({
  displayName: "FullCalendar",
  mixins: [_CommonMixin["default"], _CalendarMixin["default"]],
  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["default"];
        header = /*#__PURE__*/_react["default"].createElement(TheHeader, (0, _extends2["default"])({
          key: "calendar-header"
        }, props, {
          prefixCls: "".concat(prefixCls, "-full"),
          type: type,
          value: value,
          onTypeChange: this.setType,
          onValueChange: this.setValue
        }));
      }
    }

    var table = type === 'date' ? /*#__PURE__*/_react["default"].createElement(_DateTable["default"], {
      dateRender: props.dateCellRender,
      contentRender: props.dateCellContentRender,
      locale: locale,
      prefixCls: prefixCls,
      onSelect: this.onSelect,
      value: value,
      disabledDate: disabledDate
    }) : /*#__PURE__*/_react["default"].createElement(_MonthTable["default"], {
      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["default"].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(' ')
    });
  }
});
var _default = FullCalendar;
exports["default"] = _default;
//# sourceMappingURL=FullCalendar.js.map
