"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.useRangeDatePicker = void 0;
const react_1 = require("react");
const useBaseDatePicker_1 = __importDefault(require("../../BaseDatePicker/hooks/useBaseDatePicker"));
const index_util_1 = require("./index.util");
const types_1 = require("../../../../types");
const INIT_SELECTED_DATA = types_1.EMPTY_DATE;
const useRangeDatePicker = (props) => {
    const baseDatePicker = (0, useBaseDatePicker_1.default)(props);
    const { colorType, disabledDates, selectedStartDate, selectedEndDate, onUpdateSelectedStartDate, onUpdateSelectedEndDate, } = props;
    const handleClickDate = (0, react_1.useCallback)((val) => {
        if (selectedStartDate === types_1.EMPTY_DATE) {
            onUpdateSelectedStartDate(val);
        }
        else if (val.timestamp < selectedStartDate.timestamp) {
            onUpdateSelectedStartDate(val);
            onUpdateSelectedEndDate(types_1.EMPTY_DATE);
        }
        else if (selectedEndDate === types_1.EMPTY_DATE) {
            onUpdateSelectedEndDate(val);
        }
        else {
            onUpdateSelectedStartDate(val);
            onUpdateSelectedEndDate(types_1.EMPTY_DATE);
        }
    }, [selectedStartDate, selectedEndDate, onUpdateSelectedStartDate, onUpdateSelectedEndDate]);
    const resetSelectedData = () => {
        onUpdateSelectedStartDate(INIT_SELECTED_DATA);
        onUpdateSelectedEndDate(INIT_SELECTED_DATA);
    };
    const dateList = (0, react_1.useMemo)(() => {
        const dates = baseDatePicker.dateList;
        return (0, index_util_1.convertDatesWithRangeDatePickerFeatures)({
            dates,
            disabledDates,
            selectedStartDate,
            selectedEndDate,
            colorType,
            handleClickDate,
        });
    }, [baseDatePicker.dateList, disabledDates, colorType, selectedStartDate, selectedEndDate, handleClickDate]);
    return Object.assign(Object.assign({}, baseDatePicker), { dateList,
        resetSelectedData });
};
exports.useRangeDatePicker = useRangeDatePicker;
