import { useCallback, useEffect, useState } from 'react';
/**
 * хук для навигации в календаре по опорной дате
 */
export const useCalendarNavigate = ({ date, addCb, addDoubleCb, }) => {
    const [baseDate, setBaseDate] = useState(date);
    const handleNextClick = useCallback(() => {
        setBaseDate(addCb(baseDate, 1));
    }, [baseDate]);
    const handlePrevClick = useCallback(() => {
        setBaseDate(addCb(baseDate, -1));
    }, [baseDate]);
    const handleDoubleNextClick = useCallback(() => {
        setBaseDate(addDoubleCb?.(baseDate, 1) ?? baseDate);
    }, [baseDate]);
    const handleDoublePrevClick = useCallback(() => {
        setBaseDate(addDoubleCb?.(baseDate, -1) ?? baseDate);
    }, [baseDate]);
    useEffect(() => {
        setBaseDate(date);
    }, [date]);
    return {
        baseDate,
        handlePrevClick,
        handleNextClick,
        handleDoublePrevClick: addDoubleCb ? handleDoublePrevClick : undefined,
        handleDoubleNextClick: addDoubleCb ? handleDoubleNextClick : undefined,
    };
};
