import { useRef, useCallback } from 'react';
import { endOfDay, isAfter, isBefore } from 'date-fns';
export default function useCombinedDisabledDate(selected, disabledDate, generateDate, dateSpan) {
    if (dateSpan === void 0) { dateSpan = 0; }
    var disabledDateRef = useRef(disabledDate);
    disabledDateRef.current = disabledDate;
    var disabledCombinedDate = useCallback(function (type) { return function (value) {
        var _a;
        var date = endOfDay(value);
        var offsetDate = generateDate.offsetDate, isSame = generateDate.isSame;
        var start = selected[0], end = selected[1];
        if ((_a = disabledDateRef.current) === null || _a === void 0 ? void 0 : _a.call(disabledDateRef, date, type)) {
            return true;
        }
        if (start && !end) {
            return ((!isSame(date, start) && isBefore(date, start)) ||
                (!!dateSpan && isAfter(date, offsetDate(start, dateSpan - 1))));
        }
        return false;
    }; }, [disabledDateRef, dateSpan, generateDate, selected]);
    return disabledCombinedDate;
}
