"use strict";
Object.defineProperty(exports, "__esModule", {
    value: true
});
Object.defineProperty(exports, "DateStructureItem", {
    enumerable: true,
    get: function() {
        return DateStructureItem;
    }
});
const _react = /*#__PURE__*/ _interop_require_wildcard(require("react"));
const _utils = require("../../../../utils");
const _hooks = require("../../../../hooks");
const _Calendartokens = require("../../Calendar.tokens");
const _DateStructureItemstyles = require("./DateStructureItem.styles");
function _getRequireWildcardCache(nodeInterop) {
    if (typeof WeakMap !== "function") return null;
    var cacheBabelInterop = new WeakMap();
    var cacheNodeInterop = new WeakMap();
    return (_getRequireWildcardCache = function(nodeInterop) {
        return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
    })(nodeInterop);
}
function _interop_require_wildcard(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 = {
        __proto__: null
    };
    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;
}
const DateStructureItem = /*#__PURE__*/ (0, _react.memo)(/*#__PURE__*/ (0, _react.forwardRef)(({ children, isFocused, dayOfWeek, disabled, isCurrent, isSelected, isDayInCurrentMonth, isDouble, inRange, isHovered, sideInRange, eventList = [], day, monthIndex, year, onClick, onMouseOver, onTriggerEventTooltip, onFocus, disabledArrowKey, disabledMonths, ...rest }, outerRef)=>{
    const structureRef = (0, _react.useRef)(null);
    const innerRef = (0, _hooks.useForkRef)(outerRef, structureRef);
    const selectableClass = !dayOfWeek && !disabled ? _Calendartokens.classes.selectableItem : undefined;
    const selectedClass = isDayInCurrentMonth && isSelected ? _Calendartokens.classes.selectedItem : undefined;
    const currentClass = isDayInCurrentMonth && isCurrent ? _Calendartokens.classes.currentItem : undefined;
    const hoveredClass = isDayInCurrentMonth && isHovered ? _Calendartokens.classes.hoveredItem : undefined;
    const dayOfWeekClass = dayOfWeek ? _Calendartokens.classes.dayOfWeek : undefined;
    const dayInCurrentMonthClass = isDayInCurrentMonth ? _Calendartokens.classes.dayInCurrentMonth : undefined;
    const disabledClass = disabled && !isCurrent ? _Calendartokens.classes.disabled : undefined;
    const disabledCurrentClass = disabled && isCurrent ? _Calendartokens.classes.disabledCurrent : undefined;
    const sideInRangeLeft = isDayInCurrentMonth && sideInRange === 'left' ? _Calendartokens.classes.sideLeft : undefined;
    const sideInRangeRight = isDayInCurrentMonth && sideInRange === 'right' ? _Calendartokens.classes.sideRight : undefined;
    const sideInRangeClass = isDayInCurrentMonth && sideInRange ? _Calendartokens.classes.sideInRange : undefined;
    const inRangeStyle = isDayInCurrentMonth && inRange ? _Calendartokens.classes.inRange : undefined;
    const sideOffset = !isSelected && isCurrent ? -1 : 0;
    const handleMouseOver = (event)=>{
        if (onMouseOver) {
            onMouseOver(event);
        }
        if (onTriggerEventTooltip) {
            const eventNodes = eventList?.map(({ eventInfo })=>eventInfo).filter(Boolean) || [];
            onTriggerEventTooltip(structureRef, eventNodes);
        }
    };
    return /*#__PURE__*/ _react.default.createElement(_DateStructureItemstyles.StyledItemRoot, {
        ref: innerRef,
        className: (0, _utils.cx)(disabledClass, disabledCurrentClass, dayOfWeekClass, selectableClass, selectedClass, currentClass, hoveredClass, dayInCurrentMonthClass),
        tabIndex: isFocused ? 0 : -1,
        dayOfWeek: dayOfWeek,
        isCurrent: isCurrent,
        isSelected: isSelected,
        isDayInCurrentMonth: isDayInCurrentMonth,
        isDouble: isDouble,
        isHovered: isHovered,
        sideInRange: sideInRange,
        onClick: disabled ? undefined : onClick,
        onMouseOver: handleMouseOver,
        onFocus: onFocus,
        "data-day": day,
        "data-month-index": monthIndex,
        "data-year": year,
        "data-disabled-arrow-key": disabledArrowKey || undefined,
        "data-disabled-months": disabledMonths || undefined,
        "aria-selected": isSelected,
        "aria-disabled": disabled,
        "aria-describedby": disabled ? 'withShift' : undefined,
        ...rest
    }, /*#__PURE__*/ _react.default.createElement(_DateStructureItemstyles.StyledItem, {
        className: (0, _utils.cx)(sideInRangeClass, sideInRangeLeft, sideInRangeRight, inRangeStyle),
        offset: sideOffset
    }, children), /*#__PURE__*/ _react.default.createElement(_DateStructureItemstyles.StyledEvents, {
        "aria-hidden": true
    }, [
        eventList[0],
        eventList[1],
        eventList[2]
    ].map((event, i)=>event && /*#__PURE__*/ _react.default.createElement(_DateStructureItemstyles.StyledEvent, {
            key: `${event.date}-${i}`,
            color: event.color
        }))));
}));
