"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.StaticDaysCalendar = void 0;
const jsx_runtime_1 = require("react/jsx-runtime");
const react_1 = require("react");
const useId_1 = require("../../useId");
const checkIsDeepEqual_1 = require("../../utils/checkIsDeepEqual");
const classNames_1 = require("../../utils/classNames");
const date_1 = require("../../utils/date");
const constants_1 = require("./constants");
const DayButton_1 = require("./DayButton");
const Head_1 = require("./Head");
const styles_1 = require("./styles");
const useLogic_1 = require("./useLogic");
const StaticDaysCalendarInner = (0, react_1.memo)(({ minDate, maxDate, selectedDate, baseDate, onDayHover, hoveredDate, onChange, isMondayFirst = true, className, renderDayTooltipTitle, renderDayContent, selectedRanges, hideOutOfAvailableRangeElements, productionCalendarStorage, checkDisableTooltipInteractive, checkTooltipActive, dragAndDropProps, }) => {
    const id = (0, useId_1.useId)();
    const grid = (0, react_1.useMemo)(() => (0, date_1.buildDaysCalendarGrid)({
        baseDate,
        selectedDate,
        isMondayFirst,
        minDate,
        maxDate,
        hoveredDate,
        selectedRanges,
        productionCalendarStorage,
    }), [
        baseDate,
        selectedDate,
        maxDate,
        minDate,
        hoveredDate,
        selectedRanges,
        productionCalendarStorage,
    ]);
    const checkRenderRequirements = (0, react_1.useCallback)((item) => hideOutOfAvailableRangeElements ? !item.isOutOfAvailableRange : true, [hideOutOfAvailableRangeElements]);
    return ((0, jsx_runtime_1.jsxs)("article", { className: (0, classNames_1.classNames)(className, constants_1.staticDaysCalendarClassnames.container), children: [(0, jsx_runtime_1.jsx)(Head_1.Head, { className: constants_1.staticDaysCalendarClassnames.head, isMondayFirst: isMondayFirst, hasHolidays: Boolean(productionCalendarStorage) }), (0, jsx_runtime_1.jsx)(styles_1.Body, { role: "grid", className: constants_1.staticDaysCalendarClassnames.grid, children: grid.map((item, index) => checkRenderRequirements(item) ? ((0, jsx_runtime_1.jsx)(DayButton_1.DayButton, { className: constants_1.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
                (0, jsx_runtime_1.jsx)("div", {}, `${id}_${index}`))) })] }));
}, (prev, next) => (0, checkIsDeepEqual_1.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,
}));
const StaticDaysCalendar = ({ selectedRanges, maxDate, minDate, selectedDate, hoveredDate, isMondayFirst = true, baseDate, ...props }) => {
    const { memoizedSelectedDate, memoizedHoveredDate, memoizedSelectedRanges } = (0, useLogic_1.useLogic)({
        selectedRanges,
        selectedDate,
        hoveredDate,
        isMondayFirst,
        baseDate,
    });
    return ((0, jsx_runtime_1.jsx)(StaticDaysCalendarInner, { ...props, isMondayFirst: isMondayFirst, baseDate: baseDate, selectedDate: memoizedSelectedDate, hoveredDate: memoizedHoveredDate, selectedRanges: memoizedSelectedRanges, maxDate: maxDate, minDate: minDate }));
};
exports.StaticDaysCalendar = StaticDaysCalendar;
