"use strict";
Object.defineProperty(exports, "__esModule", {
    value: true
});
Object.defineProperty(exports, "CalendarHeader", {
    enumerable: true,
    get: function() {
        return CalendarHeader;
    }
});
const _react = /*#__PURE__*/ _interop_require_default(require("react"));
const _Icon = require("../../../_Icon");
const _types = require("../../store/types");
const _utils = require("../../utils");
const _Calendartokens = require("../../Calendar.tokens");
const _reducer = require("../../store/reducer");
const _utils1 = require("../../../../utils");
const _CalendarHeaderstyles = require("./CalendarHeader.styles");
function _interop_require_default(obj) {
    return obj && obj.__esModule ? obj : {
        default: obj
    };
}
const CalendarHeader = ({ type = 'Days', startYear = 0, size, firstDate, secondDate, isDouble, onPrev, onNext, onUpdateCalendarState, locale })=>{
    const handleCalendarState = ()=>{
        const newSize = isDouble ? _reducer.sizeMap.Months.double : _reducer.sizeMap.Months.single;
        if (type === _types.CalendarState.Days) {
            onUpdateCalendarState?.(_types.CalendarState.Months, newSize);
        }
        if (type === _types.CalendarState.Months || type === _types.CalendarState.Quarters) {
            onUpdateCalendarState?.(_types.CalendarState.Years, newSize);
        }
    };
    const handlePrev = (event)=>{
        event.stopPropagation();
        if (startYear <= 0) {
            return;
        }
        onPrev();
    };
    const handleNext = (event)=>{
        event.stopPropagation();
        onNext();
    };
    const getHeaderContent = (date, secondPart)=>{
        if (!date) {
            return '';
        }
        if (type === _types.CalendarState.Days) {
            return /*#__PURE__*/ _react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/ _react.default.createElement(_CalendarHeaderstyles.StyledHeaderDate, null, _utils.MONTH_NAMES[locale][date.monthIndex]), /*#__PURE__*/ _react.default.createElement(_CalendarHeaderstyles.StyledHeaderDate, null, date.year, /*#__PURE__*/ _react.default.createElement(_CalendarHeaderstyles.StyledHeaderArrow, {
                color: "inherit",
                size: size === 'xs' ? 'xs' : 's'
            })));
        }
        if (type === _types.CalendarState.Months || type === _types.CalendarState.Quarters) {
            return /*#__PURE__*/ _react.default.createElement(_CalendarHeaderstyles.StyledHeaderDate, null, date.year, /*#__PURE__*/ _react.default.createElement(_CalendarHeaderstyles.StyledHeaderArrow, {
                color: "inherit",
                size: size === 'xs' ? 'xs' : 's'
            }));
        }
        if (type === _types.CalendarState.Years) {
            const yearValue = secondPart ? startYear + 12 : startYear;
            return /*#__PURE__*/ _react.default.createElement(_CalendarHeaderstyles.StyledHeaderDate, null, yearValue, "—", yearValue + _utils.YEAR_RENDER_COUNT - 1, /*#__PURE__*/ _react.default.createElement(_CalendarHeaderstyles.StyledHeaderArrow, {
                color: "inherit",
                size: size === 'xs' ? 'xs' : 's'
            }));
        }
        return '';
    };
    const currentCalendarType = (0, _utils.getCalendarType)(type, locale);
    const PreviousButton = ()=>/*#__PURE__*/ _react.default.createElement(_CalendarHeaderstyles.StyledArrow, {
            className: (0, _utils1.cx)(startYear <= 0 && _Calendartokens.classes.disabledPrevButton),
            "aria-label": `${_utils.I18N.previous[locale]} ${currentCalendarType}`,
            onClick: handlePrev
        }, /*#__PURE__*/ _react.default.createElement(_Icon.IconDisclosureLeft, {
            color: "inherit",
            sizeCustomProperty: _Calendartokens.tokens.calendarArrowHeaderCustomSize
        }));
    const NextButton = ()=>/*#__PURE__*/ _react.default.createElement(_CalendarHeaderstyles.StyledArrow, {
            "aria-label": `${_utils.I18N.next[locale]} ${currentCalendarType}`,
            onClick: handleNext
        }, /*#__PURE__*/ _react.default.createElement(_Icon.IconDisclosureRight, {
            color: "inherit",
            sizeCustomProperty: _Calendartokens.tokens.calendarArrowHeaderCustomSize
        }));
    return /*#__PURE__*/ _react.default.createElement(_CalendarHeaderstyles.StyledCalendarHeader, null, isDouble ? /*#__PURE__*/ _react.default.createElement(_CalendarHeaderstyles.StyledNavigation, null, /*#__PURE__*/ _react.default.createElement(_CalendarHeaderstyles.StyledDoubleHeaderWrapper, null, /*#__PURE__*/ _react.default.createElement(PreviousButton, null), /*#__PURE__*/ _react.default.createElement(_CalendarHeaderstyles.StyledHeaderDouble, {
        onClick: handleCalendarState,
        "aria-live": "polite"
    }, getHeaderContent(firstDate))), /*#__PURE__*/ _react.default.createElement(_CalendarHeaderstyles.StyledDoubleHeaderWrapper, {
        className: _Calendartokens.classes.doubleHeaderLastDateWrapper
    }, /*#__PURE__*/ _react.default.createElement(_CalendarHeaderstyles.StyledHeaderDouble, {
        onClick: handleCalendarState,
        "aria-live": "polite"
    }, getHeaderContent(secondDate, true)), /*#__PURE__*/ _react.default.createElement(NextButton, null))) : /*#__PURE__*/ _react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/ _react.default.createElement(_CalendarHeaderstyles.StyledHeader, {
        type: "button",
        "aria-live": "polite",
        id: "id-grid-label",
        onClick: handleCalendarState,
        tabIndex: 0
    }, getHeaderContent(firstDate)), /*#__PURE__*/ _react.default.createElement(_CalendarHeaderstyles.StyledArrows, null, /*#__PURE__*/ _react.default.createElement(PreviousButton, null), /*#__PURE__*/ _react.default.createElement(NextButton, null))));
};
