"use strict";

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

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

var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));

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

var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));

var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));

var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));

var _get2 = _interopRequireDefault(require("@babel/runtime/helpers/get"));

var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));

var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));

var _createSuper2 = _interopRequireDefault(require("@babel/runtime/helpers/createSuper"));

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

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

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

var _noop = _interopRequireDefault(require("lodash/noop"));

var _DaysView2 = _interopRequireDefault(require("./DaysView"));

var _enum = require("./enum");

var _enum2 = require("../data-set/enum");

var _localeContext = require("../locale-context");

var _EventManager = require("../_util/EventManager");

var WeeksView = /*#__PURE__*/function (_DaysView) {
  (0, _inherits2["default"])(WeeksView, _DaysView);

  var _super = (0, _createSuper2["default"])(WeeksView);

  function WeeksView() {
    (0, _classCallCheck2["default"])(this, WeeksView);
    return _super.apply(this, arguments);
  }

  (0, _createClass2["default"])(WeeksView, [{
    key: "getViewClassName",
    value: function getViewClassName() {
      var prefixCls = this.prefixCls;
      return "".concat(prefixCls, "-week");
    }
  }, {
    key: "handleKeyDownLeft",
    value: function handleKeyDownLeft(e) {
      (0, _EventManager.stopEvent)(e);

      if (e.altKey) {
        this.changeViewMode(_enum.ViewMode.month);
      } else {
        this.changeCursorDate(this.getCloneDate().subtract(1, 'M'));
      }
    }
  }, {
    key: "handleKeyDownRight",
    value: function handleKeyDownRight(e) {
      (0, _EventManager.stopEvent)(e);

      if (!e.altKey) {
        this.changeCursorDate(this.getCloneDate().add(1, 'M'));
      }
    }
  }, {
    key: "renderPanelBody",
    value: function renderPanelBody() {
      var prefixCls = this.prefixCls,
          _this$props = this.props,
          date = _this$props.date,
          _this$props$renderer = _this$props.renderer,
          renderer = _this$props$renderer === void 0 ? this.renderCell : _this$props$renderer,
          onDateMouseLeave = _this$props.onDateMouseLeave;
      var selected = date.clone();
      var firstDay = this.getFirstDay(date);
      var lastDay = firstDay.clone().add(42, 'd');
      var rows = [];
      var cells = [];

      while (firstDay.isBefore(lastDay)) {
        var currentDate = firstDay.clone();
        var className = (0, _classnames["default"])("".concat(prefixCls, "-cell"), (0, _defineProperty2["default"])({}, "".concat(prefixCls, "-selected"), firstDay.isSame(selected, 'w')));
        var text = String(currentDate.date());
        var dayProps = {
          key: firstDay.format('M_D'),
          className: className,
          children: this.renderInner(text)
        };

        if (cells.length === 0) {
          var weekProps = {
            key: firstDay.format('Wo'),
            className: "".concat(className, " ").concat(prefixCls, "-week-cell")
          };
          cells.push(this.getWeekCell(weekProps, firstDay.week()));
        }

        cells.push(renderer(dayProps, text, currentDate, selected));

        if (cells.length === 8) {
          rows.push( /*#__PURE__*/_react["default"].createElement("tr", {
            onClick: this.handleCellClick.bind(this, currentDate),
            key: firstDay.format('M_D'),
            onMouseEnter: this.handleDateMouseEnter.bind(this, currentDate),
            onMouseLeave: onDateMouseLeave
          }, cells));
          cells = [];
        }

        firstDay.add(1, 'd');
      }

      return rows;
    }
  }, {
    key: "choose",
    value: function choose(date) {
      (0, _get2["default"])((0, _getPrototypeOf2["default"])(WeeksView.prototype), "choose", this).call(this, date.startOf('W'));
    }
  }, {
    key: "getPanelClass",
    value: function getPanelClass() {
      return "".concat(this.prefixCls, "-week-panel");
    }
  }, {
    key: "renderFooter",
    value: function renderFooter() {
      var _classNames2;

      var prefixCls = this.prefixCls,
          _this$props2 = this.props,
          disabledNow = _this$props2.disabledNow,
          isExistValue = _this$props2.isExistValue;
      var footerProps = {
        className: (0, _classnames["default"])("".concat(prefixCls, "-footer-now-btn"), (_classNames2 = {}, (0, _defineProperty2["default"])(_classNames2, "".concat(prefixCls, "-now-disabled"), disabledNow), (0, _defineProperty2["default"])(_classNames2, "".concat(prefixCls, "-now-selected"), isExistValue), _classNames2)),
        onClick: !disabledNow ? this.choose.bind(this, (0, _moment["default"])()) : _noop["default"]
      };
      return /*#__PURE__*/_react["default"].createElement("div", {
        className: "".concat(prefixCls, "-footer")
      }, /*#__PURE__*/_react["default"].createElement("a", (0, _extends2["default"])({}, footerProps), (0, _localeContext.$l)('DatePicker', 'this_week')));
    }
  }, {
    key: "getWeekCell",
    value: function getWeekCell(props, text) {
      var prefixCls = this.prefixCls;
      return /*#__PURE__*/_react["default"].createElement("td", (0, _extends2["default"])({}, props), /*#__PURE__*/_react["default"].createElement("div", {
        className: "".concat(prefixCls, "-cell-inner")
      }, "W", text));
    }
  }, {
    key: "getDaysOfWeek",
    value: function getDaysOfWeek() {
      return [/*#__PURE__*/_react["default"].createElement("th", {
        key: "null"
      }, "\xA0")].concat((0, _toConsumableArray2["default"])((0, _get2["default"])((0, _getPrototypeOf2["default"])(WeeksView.prototype), "getDaysOfWeek", this).call(this)));
    }
  }]);
  return WeeksView;
}(_DaysView2["default"]);

exports["default"] = WeeksView;
WeeksView.displayName = 'WeeksView';
WeeksView.type = _enum2.FieldType.week;
//# sourceMappingURL=WeeksView.js.map
