import { useState, useMemo, useEffect } from 'react';
import { parseDate, parseBase } from '../utils/index';
var current = new Date();
export default function useMergedProps(_a) {
    var value = _a.value, format = _a.format, defaultDate = _a.defaultDate;
    var _b = useState(current), defaultPanelDate = _b[0], setDefaultPanelDate = _b[1];
    var parseValue = useMemo(function () { return parseDate(format, value); }, [value, format]);
    var _c = useState(parseValue), selected = _c[0], setSelected = _c[1];
    useEffect(function () {
        setSelected(parseValue);
    }, [parseValue]);
    useEffect(function () {
        var dateValue = selected || defaultDate;
        setDefaultPanelDate(dateValue ? parseBase(dateValue, format) : current);
    }, [defaultDate, selected, value, format]);
    return {
        selected: selected,
        parseValue: parseValue,
        setSelected: setSelected,
        defaultPanelDate: defaultPanelDate,
    };
}
