"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.useCalendarNavigate = void 0;
const react_1 = require("react");
/**
 * хук для навигации в календаре по опорной дате
 */
const useCalendarNavigate = ({ date, addCb, addDoubleCb, }) => {
    const [baseDate, setBaseDate] = (0, react_1.useState)(date);
    const handleNextClick = (0, react_1.useCallback)(() => {
        setBaseDate(addCb(baseDate, 1));
    }, [baseDate]);
    const handlePrevClick = (0, react_1.useCallback)(() => {
        setBaseDate(addCb(baseDate, -1));
    }, [baseDate]);
    const handleDoubleNextClick = (0, react_1.useCallback)(() => {
        setBaseDate(addDoubleCb?.(baseDate, 1) ?? baseDate);
    }, [baseDate]);
    const handleDoublePrevClick = (0, react_1.useCallback)(() => {
        setBaseDate(addDoubleCb?.(baseDate, -1) ?? baseDate);
    }, [baseDate]);
    (0, react_1.useEffect)(() => {
        setBaseDate(date);
    }, [date]);
    return {
        baseDate,
        handlePrevClick,
        handleNextClick,
        handleDoublePrevClick: addDoubleCb ? handleDoublePrevClick : undefined,
        handleDoubleNextClick: addDoubleCb ? handleDoubleNextClick : undefined,
    };
};
exports.useCalendarNavigate = useCalendarNavigate;
