"use strict";

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

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

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

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

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

var _constant = require("../../../../../utils/constant");

require("./index.css");

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

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

var preCls = 'titaui__picker';

var WeekPanelBody = function WeekPanelBody(props) {
  var startDate = props.startDate,
      onSelect = props.onSelect,
      selectWeekDate = props.selectWeekDate;

  var getCells = function getCells(date) {
    var currentYear = (0, _utils.getWeek)(new Date(new Date()))[2];
    var currentMonth = (0, _utils.getWeek)(new Date(new Date()))[1];
    var currentWeek = (0, _utils.getWeek)(new Date(new Date()))[0];
    var year = (0, _utils.getWeek)(new Date(new Date(date)))[2]; //获取年

    var month = (0, _utils.getWeek)(new Date(new Date(date)))[1];
    var selectYear;
    var selectMonth;
    var selectWeek;

    if (selectWeekDate && typeof selectWeekDate[0] === 'string') {
      selectYear = (0, _utils.getWeek)(new Date(new Date(selectWeekDate[0])))[2];
      selectMonth = (0, _utils.getWeek)(new Date(new Date(selectWeekDate[0])))[1];
      selectWeek = (0, _utils.getWeek)(new Date(new Date(selectWeekDate[0])))[0];
    }

    var range = (0, _utils.getPointYearMonthWeeksRange)(year, month);

    if (range) {
      return range.map(function (item, i) {
        return /*#__PURE__*/_react["default"].createElement("tr", {
          key: i,
          className: (0, _classnames["default"])("".concat(preCls, "__week"), _defineProperty({}, "".concat(preCls, "__week--current"), currentWeek === i + 1 && (0, _utils.getWeek)(new Date("".concat(year, "/").concat(item.startTime)))[2] === currentYear && (0, _utils.getWeek)(new Date("".concat(year, "/").concat(item.startTime)))[1] === currentMonth), _defineProperty({}, "".concat(preCls, "__week--select"), selectWeek === i + 1 && selectYear === (0, _utils.getWeek)(new Date("".concat(year, "/").concat(item.startTime)))[2] && selectMonth === (0, _utils.getWeek)(new Date("".concat(year, "/").concat(item.startTime)))[1]))
        }, /*#__PURE__*/_react["default"].createElement("div", {
          onClick: function onClick() {
            if (onSelect) {
              onSelect(["".concat(year, "/").concat(item.startTime), "".concat(year, "/").concat(item.endTime)], 'week', year);
            }
          },
          className: "".concat(preCls, "__week-box")
        }, /*#__PURE__*/_react["default"].createElement("span", {
          className: "".concat(preCls, "__week-index")
        }, (0, _constant.getWeekly)()[i]), "".concat(item.startTime, "~").concat(item.endTime)));
      });
    } else {
      return null;
    }
  };

  return /*#__PURE__*/_react["default"].createElement("div", {
    className: (0, _classnames["default"])(_utils2.PickerBodyClass)
  }, /*#__PURE__*/_react["default"].createElement("table", {
    className: (0, _classnames["default"])("".concat(_utils2.PickerClass, "-content"))
  }, /*#__PURE__*/_react["default"].createElement("tbody", null, getCells(startDate))));
};

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