import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { useContext } from 'react';
import cls from 'clsx';
import ConfigProviderContext from '../config-provider/ConfigProviderContext';

const CalenderHeader = props => {
  const {
    prefixCls,
    createNamespace,
    locale
  } = useContext(ConfigProviderContext);
  const [bem] = createNamespace('calendar', prefixCls);

  const renderTitle = () => {
    if (props.showTitle) {
      const text = props.title || locale.vanCalendar.title;
      return _jsx("div", Object.assign({
        className: cls(bem('header-title'))
      }, {
        children: text
      }));
    }

    return null;
  };

  const onClickSubtitle = event => {
    var _a;

    (_a = props.onClickSubtitle) === null || _a === void 0 ? void 0 : _a.call(props, event);
  };

  const renderSubtitle = () => {
    if (props.showSubtitle) {
      return _jsx("div", Object.assign({
        className: cls(bem('header-subtitle')),
        onClick: onClickSubtitle
      }, {
        children: props.subtitle
      }));
    }

    return null;
  };

  const renderWeekDays = () => {
    const {
      weekdays: customWeekdays,
      firstDayOfWeek
    } = props;
    const defaultWeekdays = locale.vanCalendar.weekdays;
    const weekdays = customWeekdays ? defaultWeekdays.map((wk, i) => customWeekdays[i] || wk) : defaultWeekdays;
    const renderWeekDaysContent = [...weekdays.slice(firstDayOfWeek, 7), ...weekdays.slice(0, firstDayOfWeek)];
    return _jsx("div", Object.assign({
      className: cls(bem('weekdays'))
    }, {
      children: renderWeekDaysContent.map((text, i) => // eslint-disable-next-line react/no-array-index-key
      _jsx("span", Object.assign({
        className: cls(bem('weekday'))
      }, {
        children: text
      }), i))
    }));
  };

  return _jsxs("div", Object.assign({
    className: cls(bem('header'))
  }, {
    children: [renderTitle(), renderSubtitle(), renderWeekDays()]
  }));
};

export default CalenderHeader;