"use strict";

exports.__esModule = true;
exports.default = void 0;

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

var _clsx = _interopRequireDefault(require("clsx"));

var _ConfigProviderContext = _interopRequireDefault(require("../config-provider/ConfigProviderContext"));

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; }

var CalenderHeader = function CalenderHeader(props) {
  var _useContext = (0, _react.useContext)(_ConfigProviderContext.default),
      prefixCls = _useContext.prefixCls,
      createNamespace = _useContext.createNamespace,
      locale = _useContext.locale;

  var _createNamespace = createNamespace('calendar', prefixCls),
      bem = _createNamespace[0];

  var renderTitle = function renderTitle() {
    if (props.showTitle) {
      var text = props.title || locale.vanCalendar.title;
      return /*#__PURE__*/_react.default.createElement("div", {
        className: (0, _clsx.default)(bem('header-title'))
      }, text);
    }

    return null;
  };

  var onClickSubtitle = function onClickSubtitle(event) {
    props.onClickSubtitle == null ? void 0 : props.onClickSubtitle(event);
  };

  var renderSubtitle = function renderSubtitle() {
    if (props.showSubtitle) {
      return /*#__PURE__*/_react.default.createElement("div", {
        className: (0, _clsx.default)(bem('header-subtitle')),
        onClick: onClickSubtitle
      }, props.subtitle);
    }

    return null;
  };

  var renderWeekDays = function renderWeekDays() {
    var customWeekdays = props.weekdays,
        firstDayOfWeek = props.firstDayOfWeek;
    var defaultWeekdays = locale.vanCalendar.weekdays;
    var weekdays = customWeekdays ? defaultWeekdays.map(function (wk, i) {
      return customWeekdays[i] || wk;
    }) : defaultWeekdays;
    var renderWeekDaysContent = [].concat(weekdays.slice(firstDayOfWeek, 7), weekdays.slice(0, firstDayOfWeek));
    return /*#__PURE__*/_react.default.createElement("div", {
      className: (0, _clsx.default)(bem('weekdays'))
    }, renderWeekDaysContent.map(function (text, i) {
      return (
        /*#__PURE__*/
        // eslint-disable-next-line react/no-array-index-key
        _react.default.createElement("span", {
          key: i,
          className: (0, _clsx.default)(bem('weekday'))
        }, text)
      );
    }));
  };

  return /*#__PURE__*/_react.default.createElement("div", {
    className: (0, _clsx.default)(bem('header'))
  }, renderTitle(), renderSubtitle(), renderWeekDays());
};

var _default = CalenderHeader;
exports.default = _default;