import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { memo, useCallback, useMemo } from 'react';
import { useId } from '../../useId';
import { checkIsDeepEqual } from '../../utils/checkIsDeepEqual';
import { classNames } from '../../utils/classNames';
import { buildDaysCalendarGrid, } from '../../utils/date';
import { staticDaysCalendarClassnames } from './constants';
import { DayButton } from './DayButton';
import { Head } from './Head';
import { Body } from './styles';
import { useLogic } from './useLogic';
const StaticDaysCalendarInner = memo(({ minDate, maxDate, selectedDate, baseDate, onDayHover, hoveredDate, onChange, isMondayFirst = true, className, renderDayTooltipTitle, renderDayContent, selectedRanges, hideOutOfAvailableRangeElements, productionCalendarStorage, checkDisableTooltipInteractive, checkTooltipActive, dragAndDropProps, }) => {
    const id = useId();
    const grid = useMemo(() => buildDaysCalendarGrid({
        baseDate,
        selectedDate,
        isMondayFirst,
        minDate,
        maxDate,
        hoveredDate,
        selectedRanges,
        productionCalendarStorage,
    }), [
        baseDate,
        selectedDate,
        maxDate,
        minDate,
        hoveredDate,
        selectedRanges,
        productionCalendarStorage,
    ]);
    const checkRenderRequirements = useCallback((item) => hideOutOfAvailableRangeElements ? !item.isOutOfAvailableRange : true, [hideOutOfAvailableRangeElements]);
    return (_jsxs("article", { className: classNames(className, staticDaysCalendarClassnames.container), children: [_jsx(Head, { className: staticDaysCalendarClassnames.head, isMondayFirst: isMondayFirst, hasHolidays: Boolean(productionCalendarStorage) }), _jsx(Body, { role: "grid", className: staticDaysCalendarClassnames.grid, children: grid.map((item, index) => checkRenderRequirements(item) ? (_jsx(DayButton, { className: staticDaysCalendarClassnames.button, isPreviousItemInSelectedRange: grid[index - 1]?.isInSelectedRange, isNextItemInSelectedRange: grid[index + 1]?.isInSelectedRange, isPreviousItemInHoveredRange: grid[index - 1]?.isInHoveredRange, isNextItemInHoveredRange: grid[index + 1]?.isInHoveredRange, ...item, onClick: onChange, onDayHover: onDayHover, renderDayTooltipTitle: renderDayTooltipTitle, disableTooltipInteractive: checkDisableTooltipInteractive?.(item), renderDayContent: renderDayContent, dragAndDropProps: dragAndDropProps, checkTooltipActive: checkTooltipActive }, item.date.toString())) : (
                // biome-ignore lint/suspicious/noArrayIndexKey: Используется вместе с keyId
                _jsx("div", {}, `${id}_${index}`))) })] }));
}, (prev, next) => checkIsDeepEqual({
    baseDate: prev.baseDate,
    selectedDate: prev.selectedDate,
    isMondayFirst: prev.isMondayFirst,
    minDate: prev.minDate,
    maxDate: prev.maxDate,
    hoveredDate: prev.hoveredDate,
    selectedRanges: prev.selectedRanges,
    renderDayContent: prev.renderDayContent,
    renderDayTooltipTitle: prev.renderDayTooltipTitle,
    dragAndDropProps: prev.dragAndDropProps,
}, {
    baseDate: next.baseDate,
    selectedDate: next.selectedDate,
    isMondayFirst: next.isMondayFirst,
    minDate: next.minDate,
    maxDate: next.maxDate,
    hoveredDate: next.hoveredDate,
    selectedRanges: next.selectedRanges,
    renderDayContent: next.renderDayContent,
    renderDayTooltipTitle: next.renderDayTooltipTitle,
    dragAndDropProps: next.dragAndDropProps,
}));
export const StaticDaysCalendar = ({ selectedRanges, maxDate, minDate, selectedDate, hoveredDate, isMondayFirst = true, baseDate, ...props }) => {
    const { memoizedSelectedDate, memoizedHoveredDate, memoizedSelectedRanges } = useLogic({
        selectedRanges,
        selectedDate,
        hoveredDate,
        isMondayFirst,
        baseDate,
    });
    return (_jsx(StaticDaysCalendarInner, { ...props, isMondayFirst: isMondayFirst, baseDate: baseDate, selectedDate: memoizedSelectedDate, hoveredDate: memoizedHoveredDate, selectedRanges: memoizedSelectedRanges, maxDate: maxDate, minDate: minDate }));
};
