"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.initializeDriverInPage = initializeDriverInPage;
exports.setSessionInfo = setSessionInfo;
exports.getSessionInfo = getSessionInfo;
exports.getDriver = getDriver;
const web2driver_1 = require("web2driver");
let MABL_SESSION_CONFIG;
let MABL_APPIUM_DRIVER;
async function initializeDriverInPage(config) {
    const driver = await web2driver_1.Web2Driver.attachToSession(config.sessionId, {
        protocol: config.protocol ?? 'http',
        hostname: config.hostname ?? 'localhost',
        port: config.port ?? 4723,
        path: config.path ?? '/',
        isMobile: config.isMobile ?? false,
        isAndroid: config.isAndroid ?? false,
        isIOS: config.isIOS ?? false,
    }, config.capabilities, config.isW3C ?? true);
    return driver;
}
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,
};
