"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    var desc = Object.getOwnPropertyDescriptor(m, k);
    if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
      desc = { enumerable: true, get: function() { return m[k]; } };
    }
    Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
    var ownKeys = function(o) {
        ownKeys = Object.getOwnPropertyNames || function (o) {
            var ar = [];
            for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
            return ar;
        };
        return ownKeys(o);
    };
    return function (mod) {
        if (mod && mod.__esModule) return mod;
        var result = {};
        if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
        __setModuleDefault(result, mod);
        return result;
    };
})();
var __rest = (this && this.__rest) || function (s, e) {
    var t = {};
    for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
        t[p] = s[p];
    if (s != null && typeof Object.getOwnPropertySymbols === "function")
        for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
            if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
                t[p[i]] = s[p[i]];
        }
    return t;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const classnames_1 = __importDefault(require("classnames"));
const react_1 = __importStar(require("react"));
const DateRangePicker_1 = __importDefault(require("./DateRangePicker"));
const Overlay_1 = require("../Overlay/Overlay");
const BookingWizard_1 = require("../BookingWizard/BookingWizard");
const DateRangePicker_module_scss_1 = __importDefault(require("./DateRangePicker.module.scss"));
const FloatingDateRangePicker = react_1.default.forwardRef((props, ref) => {
    var _a, _b;
    const { children, notes, startDate: startDateProp, endDate: endDateProp, selectedDateChanged: selectedDateChangedProp, className, overlay, showYearOnCalendar, yearDisplayOption, onOverlayOpenChange } = props, DatePickerProps = __rest(props, ["children", "notes", "startDate", "endDate", "selectedDateChanged", "className", "overlay", "showYearOnCalendar", "yearDisplayOption", "onOverlayOpenChange"]);
    const [isOpen, setIsOpen] = (0, react_1.useState)(false);
    const [startDate, setStartDate] = (0, react_1.useState)(null);
    const thisElement = (0, react_1.useRef)(null);
    react_1.default.useImperativeHandle(ref, () => ({
        closePicker: onOverlayClose,
        openPicker: onOverlayOpen,
        toggle: () => setIsOpen(!isOpen),
    }), []);
    const selectedDateChanged = (endDate) => {
        if (selectedDateChangedProp && startDate) {
            selectedDateChangedProp(startDate, endDate);
        }
        if (endDate) {
            setIsOpen(false);
        }
    };
    const onStartDateChangedHandler = (date) => {
        setStartDate(date);
    };
    const onOverlayClose = () => {
        setIsOpen(false);
    };
    const onOverlayOpen = () => {
        setIsOpen(true);
    };
    (0, react_1.useEffect)(() => {
        onOverlayOpenChange === null || onOverlayOpenChange === void 0 ? void 0 : onOverlayOpenChange(isOpen);
        return () => {
            onOverlayOpenChange === null || onOverlayOpenChange === void 0 ? void 0 : onOverlayOpenChange(false);
        };
    }, [isOpen]);
    const inner = (react_1.default.createElement("div", { className: "d-flex align-items-center flex-column" },
        react_1.default.createElement(DateRangePicker_1.default, Object.assign({ selectedStartDate: startDateProp, selectedEndDate: endDateProp, onStartDateChanged: onStartDateChangedHandler, onEndDateChanged: selectedDateChanged, showYearOnCalendar: showYearOnCalendar, yearDisplayOption: yearDisplayOption }, DatePickerProps))));
    return (react_1.default.createElement(react_1.default.Fragment, null,
        react_1.default.createElement("div", { ref: thisElement, className: className, onClick: onOverlayOpen }, children),
        react_1.default.createElement(Overlay_1.Overlay, Object.assign({ offset: props.overlayOffset, open: isOpen, onClose: onOverlayClose, container: props.container || ((_b = (_a = thisElement.current) === null || _a === void 0 ? void 0 : _a.parentElement) === null || _b === void 0 ? void 0 : _b.parentElement), followElement: props.container || thisElement.current }, (overlay || {}), { className: (0, classnames_1.default)(DateRangePicker_module_scss_1.default['floating-roomstay-calendar'], {
                [DateRangePicker_module_scss_1.default['--small']]: DatePickerProps.small,
                [DateRangePicker_module_scss_1.default['--specific']]: props.theme === BookingWizard_1.EBookingWizardTheme.Specific,
                [DateRangePicker_module_scss_1.default['--images']]: props.theme === BookingWizard_1.EBookingWizardTheme.Images,
                [DateRangePicker_module_scss_1.default['--single']]: !DatePickerProps.showMultipleMonths,
            }) }),
            inner,
            notes)));
});
FloatingDateRangePicker.displayName = 'FloatingDateRangePicker';
exports.default = FloatingDateRangePicker;
//# sourceMappingURL=FloatingDateRangePicker.js.map