"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.BaseEngine = exports.BookingEngineSource = void 0;
const RoomstayThemeEngine_1 = __importDefault(require("../providers/RoomstayThemeEngine"));
const LocalStorageProvider_1 = __importDefault(require("../providers/storage/LocalStorageProvider"));
const SessionProvider_1 = __importDefault(require("../providers/storage/SessionProvider"));
var BookingEngineSource;
(function (BookingEngineSource) {
    BookingEngineSource["Inline"] = "inline";
    BookingEngineSource["RecentSearches"] = "recent-searches";
    BookingEngineSource["Fullpage"] = "fullpage";
    BookingEngineSource["BookingWizard"] = "booking-wizard";
    BookingEngineSource["Auth"] = "auth";
})(BookingEngineSource || (exports.BookingEngineSource = BookingEngineSource = {}));
class BaseEngine {
    constructor(bookingContainer, config) {
        this.start = () => __awaiter(this, void 0, void 0, function* () {
            const queryParams = new URLSearchParams(window.location.hash.replace(/^#\/.+\//, ''));
            let sessionId = null;
            if (queryParams) {
                if (queryParams.has('session')) {
                    sessionId = queryParams.get('session');
                }
            }
            this.sessionProvider = new SessionProvider_1.default();
            this.sessionProvider.initialize(sessionId, this.source).then(() => __awaiter(this, void 0, void 0, function* () {
                this.initialSession = yield this.sessionProvider.getSession();
            }));
            this.storageProvider = new LocalStorageProvider_1.default();
            setTimeout(() => {
                this.render();
            }, 1);
        });
        this.bookingContainer = bookingContainer;
        this.bookingContainer.classList.add('roomstay-booking-container');
        if (this.engineConfig) {
            this.setConfig(config);
        }
        // TODO: Update these calls
        RoomstayThemeEngine_1.default.EngineContainer = bookingContainer;
        RoomstayThemeEngine_1.default.init();
    }
    getInitialSession() {
        if (this.initialSession) {
            return this.initialSession;
        }
        console.error('Tried Loading session without engine initializing first.');
        return null;
    }
    getSessionProvider() {
        return this.sessionProvider;
    }
    getStorageProvider() {
        return this.storageProvider;
    }
    setConfig(config) {
        // TODO: add hook updates in here.
        this.engineConfig = config;
    }
    getConfig() {
        return this.engineConfig;
    }
    getSource() {
        return this.source;
    }
}
exports.BaseEngine = BaseEngine;
//# sourceMappingURL=BaseEngine.js.map