"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.initializeDriverInPage = initializeDriverInPage;
exports.setSessionInfo = setSessionInfo;
exports.getSessionInfo = getSessionInfo;
exports.getDriver = getDriver;
const session_1 = require("./client/session");
let MABL_SESSION_CONFIG;
let MABL_APPIUM_DRIVER;
function initializeDriverInPage(config) {
    return Promise.resolve((0, session_1.attachToSession)(config.sessionId, {
        protocol: config.protocol ?? 'http',
        hostname: config.hostname ?? 'localhost',
        port: config.port ?? 4723,
        path: config.path ?? '/',
    }, config.capabilities));
}
function setSessionInfo(config) {
    MABL_SESSION_CONFIG = config;
}
function getSessionInfo() {
    return MABL_SESSION_CONFIG;
}
async function getDriver() {
    if (!MABL_APPIUM_DRIVER) {
        MABL_APPIUM_DRIVER = await initializeDriverInPage(MABL_SESSION_CONFIG);
    }
    return MABL_APPIUM_DRIVER;
}
window.mabl = {
    mobile: {
        initializeDriverInPage,
        setSessionInfo,
        getSessionInfo,
        getDriver,
    },
    ...window._mabl,
};
