import React, { useContext } from 'react';
import cls from 'clsx';
import ConfigProviderContext from '../config-provider/ConfigProviderContext';

var CalenderHeader = function CalenderHeader(props) {
  var _useContext = useContext(ConfigProviderContext),
      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.createElement("div", {
        className: cls(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.createElement("div", {
        className: cls(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.createElement("div", {
      className: cls(bem('weekdays'))
    }, renderWeekDaysContent.map(function (text, i) {
      return (
        /*#__PURE__*/
        // eslint-disable-next-line react/no-array-index-key
        React.createElement("span", {
          key: i,
          className: cls(bem('weekday'))
        }, text)
      );
    }));
  };

  return /*#__PURE__*/React.createElement("div", {
    className: cls(bem('header'))
  }, renderTitle(), renderSubtitle(), renderWeekDays());
};

export default CalenderHeader;