"use strict";
Object.defineProperty(exports, "__esModule", {
    value: true
});
Object.defineProperty(exports, "CalendarHeader", {
    enumerable: true,
    get: function() {
        return CalendarHeader;
    }
});
var _react = /*#__PURE__*/ _interop_require_default(require("react"));
var _Icon = require("../../../_Icon");
var _types = require("../../store/types");
var _utils = require("../../utils");
var _Calendartokens = require("../../Calendar.tokens");
var _reducer = require("../../store/reducer");
var _utils1 = require("../../../../utils");
var _CalendarHeaderstyles = require("./CalendarHeader.styles");
function _interop_require_default(obj) {
    return obj && obj.__esModule ? obj : {
        default: obj
    };
}
var CalendarHeader = function CalendarHeader(param) {
    var _param_type = param.type, type = _param_type === void 0 ? 'Days' : _param_type, _param_startYear = param.startYear, startYear = _param_startYear === void 0 ? 0 : _param_startYear, size = param.size, firstDate = param.firstDate, secondDate = param.secondDate, isDouble = param.isDouble, onPrev = param.onPrev, onNext = param.onNext, onUpdateCalendarState = param.onUpdateCalendarState, locale = param.locale;
    var handleCalendarState = function handleCalendarState() {
        var newSize = isDouble ? _reducer.sizeMap.Months.double : _reducer.sizeMap.Months.single;
        if (type === _types.CalendarState.Days) {
            onUpdateCalendarState === null || onUpdateCalendarState === void 0 ? void 0 : onUpdateCalendarState(_types.CalendarState.Months, newSize);
        }
        if (type === _types.CalendarState.Months || type === _types.CalendarState.Quarters) {
            onUpdateCalendarState === null || onUpdateCalendarState === void 0 ? void 0 : onUpdateCalendarState(_types.CalendarState.Years, newSize);
        }
    };
    var handlePrev = function handlePrev(event) {
        event.stopPropagation();
        if (startYear <= 0) {
            return;
        }
        onPrev();
    };
    var handleNext = function handleNext(event) {
        event.stopPropagation();
        onNext();
    };
    var getHeaderContent = function 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) {
            var 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 '';
    };
    var currentCalendarType = (0, _utils.getCalendarType)(type, locale);
    var PreviousButton = function PreviousButton() {
        return /*#__PURE__*/ _react.default.createElement(_CalendarHeaderstyles.StyledArrow, {
            className: (0, _utils1.cx)(startYear <= 0 && _Calendartokens.classes.disabledPrevButton),
            "aria-label": "".concat(_utils.I18N.previous[locale], " ").concat(currentCalendarType),
            onClick: handlePrev
        }, /*#__PURE__*/ _react.default.createElement(_Icon.IconDisclosureLeft, {
            color: "inherit",
            sizeCustomProperty: _Calendartokens.tokens.calendarArrowHeaderCustomSize
        }));
    };
    var NextButton = function NextButton() {
        return /*#__PURE__*/ _react.default.createElement(_CalendarHeaderstyles.StyledArrow, {
            "aria-label": "".concat(_utils.I18N.next[locale], " ").concat(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))));
};
