"use strict";

function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }

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

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

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

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

var _getLocale = require("../../../../../utils/getLocale");

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

var _context = _interopRequireDefault(require("../../../context"));

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

function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }

function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }

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 MONTH_ROW_NUM = 4;
var MONTH_COL_NUM = 3;

var MonthPanelBody = function MonthPanelBody(props) {
  var viewDate = props.viewDate,
      onSelect = props.onSelect;

  var _useContext = (0, _react.useContext)(_context["default"]),
      value = _useContext.value;

  var getCells = function getCells(baseMonth) {
    var cols = [];

    var _loop = function _loop(col) {
      var _classNames;

      var month = col + baseMonth;
      cols.push( /*#__PURE__*/_react["default"].createElement("td", {
        className: (0, _classnames["default"])(_utils.PickerCellClass, "".concat(_utils.PickerCellClass, "--in-view"), (_classNames = {}, _defineProperty(_classNames, "".concat(_utils.PickerCellClass, "--this-month"), month === (0, _moment["default"])().month()), _defineProperty(_classNames, "".concat(_utils.PickerCellClass, "--selected"), month === (0, _moment["default"])(viewDate).month()), _classNames)),
        key: month
      }, /*#__PURE__*/_react["default"].createElement("div", {
        onClick: function onClick() {
          return onSelect && onSelect((0, _moment["default"])(viewDate).month(month), 'month');
        },
        className: (0, _classnames["default"])("".concat(_utils.PickerCellClass, "__inner")),
        title: (0, _moment["default"])(viewDate).month(month).format('YYYY-MM')
      }, _getLocale.isEn ? _utils.MONTHDATAMAPEN[month] : _utils.MONTHDATAMAP[month])));
    };

    for (var col = 0; col < MONTH_COL_NUM; col += 1) {
      _loop(col);
    }

    return cols;
  };

  var getRows = function getRows() {
    var rows = [];
    var baseMonth = 0;

    for (var row = 0; row < MONTH_ROW_NUM; row += 1) {
      rows.push( /*#__PURE__*/_react["default"].createElement("tr", {
        key: row
      }, getCells(baseMonth)));
      baseMonth += MONTH_COL_NUM;
    }

    return rows;
  };

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

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