import { __assign, __rest } from "tslib";
import { useRef, useMemo } from 'react';
import { startOfToday, endOfToday } from 'date-fns';
import { formatBase } from '../utils/index';
import { TIME_FORMAT } from '../constants';
var formatStartDate = function (format) { return formatBase(startOfToday(), format); };
var formatEndDate = function (format) { return formatBase(endOfToday(), format); };
var DefaultStartTime = formatStartDate(TIME_FORMAT);
var DefaultEndTime = formatEndDate(TIME_FORMAT);
export function useShowTimeRangeOption(showTime) {
    var showTimeRef = useRef(showTime);
    showTimeRef.current = showTime;
    var showTimeOption = useMemo(function () {
        if (!showTimeRef.current) {
            return [undefined, undefined];
        }
        if (typeof showTimeRef.current === 'object') {
            var _a = showTimeRef.current, _b = _a.format, format = _b === void 0 ? TIME_FORMAT : _b, defaultTime = _a.defaultTime, restOption = __rest(_a, ["format", "defaultTime"]);
            var defaultTimeStart = (defaultTime === null || defaultTime === void 0 ? void 0 : defaultTime[0]) || formatStartDate(format);
            var defaultTimeEnd = (defaultTime === null || defaultTime === void 0 ? void 0 : defaultTime[1]) || formatEndDate(format);
            return [
                __assign({ format: format, defaultTime: defaultTimeStart }, restOption),
                __assign({ format: format, defaultTime: defaultTimeEnd }, restOption),
            ];
        }
        return [
            {
                format: TIME_FORMAT,
                defaultTime: DefaultStartTime,
            },
            {
                format: TIME_FORMAT,
                defaultTime: DefaultEndTime,
            },
        ];
    }, [showTimeRef]);
    return showTimeOption;
}
export function useShowTimeOption(showTime) {
    var showTimeRef = useRef(showTime);
    showTimeRef.current = showTime;
    var showTimeOption = useMemo(function () {
        if (!showTimeRef.current) {
            return undefined;
        }
        if (typeof showTimeRef.current === 'object') {
            var _a = showTimeRef.current, _b = _a.format, format = _b === void 0 ? TIME_FORMAT : _b, defaultTime = _a.defaultTime, restOption = __rest(_a, ["format", "defaultTime"]);
            var defaultTimeTemp = defaultTime || formatStartDate(format);
            return __assign({ format: format, defaultTime: defaultTimeTemp }, restOption);
        }
        return {
            format: TIME_FORMAT,
            defaultTime: DefaultStartTime,
        };
    }, [showTimeRef]);
    return showTimeOption;
}
