"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 __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.BookingEngineContextWrapper = BookingEngineContextWrapper;
const contexts_1 = require("../index.js");
const react_1 = __importStar(require("react"));
const RoomSortProvider_1 = require("../../providers/RoomSortProvider");
const ScreenSize_1 = __importDefault(require("../../util/ScreenSize"));
function BookingEngineContextWrapper({ engine, children }) {
    const sessionProvider = engine.getSessionProvider();
    const storageProvider = engine.getStorageProvider();
    const [screenSize, setScreenSize] = (0, react_1.useState)(null);
    const [currentRoomSort, setCurrentRoomSort] = (0, react_1.useState)(RoomSortProvider_1.RoomSort.PriceLow);
    const [currentRoomRateSort, setCurrentRoomRateSort] = (0, react_1.useState)(undefined);
    const [currentFilters, setCurrentFilters] = (0, react_1.useState)({});
    const [currentGroupedRoomFilters, setCurrentGroupedRoomFilters] = (0, react_1.useState)({});
    // Persists state for RoomRateDetailsAndPriceBreakdownModal
    const [roomRateCalendarInteractivity, setRoomRateCalendarInteractivity] = (0, react_1.useState)(null);
    (0, react_1.useEffect)(() => {
        let isCancelled = false;
        const onResize = () => {
            if (!isCancelled) {
                for (const size in ScreenSize_1.default) {
                    if (window.innerWidth <= Number(size)) {
                        setScreenSize(Number(size));
                        break;
                    }
                }
            }
        };
        onResize();
        window.addEventListener('resize', onResize);
        return () => {
            isCancelled = true;
            window.removeEventListener('resize', onResize);
        };
    }, []);
    const bookingEngineContext = {
        currentRoomSort,
        currentRoomRateSort,
        currentFilters,
        currentGroupedRoomFilters,
        screenSize: screenSize,
        // Setters
        setCurrentRoomSort,
        setCurrentRoomRateSort,
        setCurrentFilters,
        setCurrentGroupedRoomFilters,
        engine,
        sessionProvider,
        storageProvider,
        roomRateCalendarInteractivity,
        setRoomRateCalendarInteractivity,
    };
    return react_1.default.createElement(contexts_1.BookingEngineContext.Provider, { value: bookingEngineContext }, children);
}
//# sourceMappingURL=BookingEngineContextWrapper.js.map