"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.useRangeDatePickerModal = void 0;
const react_1 = require("react");
const useRangeDatePicker_1 = require("../RangeDatePicker/hooks/useRangeDatePicker");
const index_util_1 = require("../BaseDatePicker/hooks/index.util");
const types_1 = require("../../../types");
const INIT_SELECTED_DATA = types_1.EMPTY_DATE;
const today = new types_1.PurpleDate().today;
const useRangeDatePickerModal = (props) => {
    const [visibleModal, setVisibleModal] = (0, react_1.useState)(false);
    const [tempSelectedStartDate, setTempSelectedStartDate] = (0, react_1.useState)(INIT_SELECTED_DATA);
    const [tempSelectedEndDate, setTempSelectedEndDate] = (0, react_1.useState)(INIT_SELECTED_DATA);
    const selectedStartDisplayDate = (0, index_util_1.convertDateToDisplayString)(tempSelectedStartDate, props.defaultSelectedStartDisplayDate);
    const selectedEndDisplayDate = (0, index_util_1.convertDateToDisplayString)(tempSelectedEndDate, props.defaultSelectedEndDisplayDate);
    const rightDisabled = !(tempSelectedStartDate && tempSelectedEndDate);
    const baseDatePicker = (0, useRangeDatePicker_1.useRangeDatePicker)(Object.assign(Object.assign({}, props), { 
        // 모달 내 임시 value, setter
        selectedStartDate: tempSelectedStartDate, selectedEndDate: tempSelectedEndDate, onUpdateSelectedStartDate: setTempSelectedStartDate, onUpdateSelectedEndDate: setTempSelectedEndDate }));
    const openModal = () => {
        setVisibleModal(true);
        props.onUpdateDisplayDate(props.selectedStartDate || today);
        setTempSelectedStartDate(props.selectedStartDate);
        setTempSelectedEndDate(props.selectedEndDate);
    };
    const closeModal = () => {
        setVisibleModal(false);
    };
    const onReset = () => {
        baseDatePicker.resetSelectedData();
    };
    const onConfirm = () => {
        props.onUpdateSelectedStartDate(tempSelectedStartDate);
        props.onUpdateSelectedEndDate(tempSelectedEndDate);
        closeModal();
    };
    return Object.assign(Object.assign({}, baseDatePicker), { selectedStartDisplayDate,
        selectedEndDisplayDate,
        visibleModal,
        rightDisabled,
        openModal,
        closeModal,
        onReset,
        onConfirm });
};
exports.useRangeDatePickerModal = useRangeDatePickerModal;
