"use strict";

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

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

var _classnames = _interopRequireDefault(require("classnames"));

var _moment = _interopRequireDefault(require("moment"));

var _utils = require("../../../utils");

var _weekHead = _interopRequireDefault(require("./week-head"));

var _weekBody = _interopRequireDefault(require("./week-body"));

var _utils2 = require("./utils");

require("./index.css");

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }

function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }

var DatePanel = function DatePanel(props) {
  var viewDate = props.viewDate,
      onViewDateChange = props.onViewDateChange,
      selectWeekDate = props.selectWeekDate;
  var startDate = viewDate[0];

  var onMonthChange = function onMonthChange(diff) {
    if (onViewDateChange) {
      if (typeof startDate === 'string') {
        onViewDateChange((0, _moment["default"])("".concat(new Date(startDate).getFullYear(), "/").concat(new Date(startDate).getMonth() + 1, "/15")).add(diff, "M"));
      } else {
        var startYear = (0, _utils2.getWeek)(new Date(startDate))[2];
        var startMonth = (0, _utils2.getWeek)(new Date(startDate))[1];
        onViewDateChange((0, _moment["default"])("".concat(startYear, "/").concat(startMonth, "/15")).add(diff, "M")); //日期写死15 是因为这里是控制头部的月的显示，如果日期为归类上一个月的，头部会乱
      }
    }
  };

  return /*#__PURE__*/_react["default"].createElement("div", {
    className: (0, _classnames["default"])("".concat(_utils.PickerPanelClass, "__week"))
  }, /*#__PURE__*/_react["default"].createElement(_weekHead["default"], _extends({}, props, {
    startDate: startDate,
    onPrev: function onPrev() {
      return onMonthChange(-1);
    },
    onNext: function onNext() {
      return onMonthChange(1);
    }
  })), /*#__PURE__*/_react["default"].createElement(_weekBody["default"], _extends({}, props, {
    startDate: viewDate[0],
    selectWeekDate: selectWeekDate
  })));
};

var _default = DatePanel;
exports["default"] = _default;