"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 (mod) {
    if (mod && mod.__esModule) return mod;
    var result = {};
    if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
    __setModuleDefault(result, mod);
    return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.performAction = exports.getElementAttribute = exports.getElementRegion = exports.getCurrentWorld = exports.visit = exports.getTitle = exports.getUrl = exports.getOrientation = exports.setWindowSize = exports.getWindowSize = exports.getDriverInfo = exports.takeScreenshot = exports.childContext = exports.parentContext = exports.mainContext = exports.getElementText = exports.findElements = exports.findElement = exports.executeScript = exports.isEqualElements = exports.isStaleElementError = exports.extractSelector = exports.toSimpleCommonSelector = exports.toSelector = exports.isSelector = exports.isElement = exports.isDriver = void 0;
const utils = __importStar(require("@applitools/utils"));
function isDriver(driver) {
    return driver && driver.constructor.name === 'MockDriver';
}
exports.isDriver = isDriver;
function isElement(element) {
    if ((element === null || element === void 0 ? void 0 : element.notting) === true)
        return false;
    return utils.types.has(element, 'id');
}
exports.isElement = isElement;
function isSelector(selector) {
    if ((selector === null || selector === void 0 ? void 0 : selector.notting) === true)
        return false;
    return (utils.types.isString(selector) || utils.types.has(selector, ['using', 'value']) || (selector === null || selector === void 0 ? void 0 : selector.forceSelector) === true);
}
exports.isSelector = isSelector;
function toSelector(selector) {
    return utils.types.has(selector, 'selector') ? selector.selector : selector;
}
exports.toSelector = toSelector;
function toSimpleCommonSelector(selector) {
    if (utils.types.isString(selector)) {
        return { type: 'css', selector: selector };
    }
    else if (utils.types.has(selector, ['using', 'value'])) {
        return { type: selector.using === 'css selector' ? 'css' : selector.using, selector: selector.value };
    }
    else if (utils.types.has(selector, ['selector'])) {
        return selector;
    }
    return null;
}
exports.toSimpleCommonSelector = toSimpleCommonSelector;
function extractSelector(element) {
    if (utils.types.has(element, ['selector'])) {
        return element.selector;
    }
}
exports.extractSelector = extractSelector;
function isStaleElementError() {
    return false;
}
exports.isStaleElementError = isStaleElementError;
async function isEqualElements(_driver, element1, element2) {
    return element1.id === element2.id;
}
exports.isEqualElements = isEqualElements;
async function executeScript(driver, script, arg) {
    return driver.executeScript(script, [arg]);
}
exports.executeScript = executeScript;
async function findElement(driver, selector, parent) {
    return driver.findElement(selector, parent);
}
exports.findElement = findElement;
async function findElements(driver, selector, parent) {
    return driver.findElements(selector, parent);
}
exports.findElements = findElements;
async function getElementText(_driver, element) {
    var _a;
    return (_a = element.attrs) === null || _a === void 0 ? void 0 : _a.text;
}
exports.getElementText = getElementText;
async function mainContext(driver) {
    return driver.switchToFrame(null);
}
exports.mainContext = mainContext;
async function parentContext(driver) {
    return driver.switchToParentFrame();
}
exports.parentContext = parentContext;
async function childContext(driver, element) {
    return driver.switchToFrame(element);
}
exports.childContext = childContext;
async function takeScreenshot(driver) {
    return driver.takeScreenshot();
}
exports.takeScreenshot = takeScreenshot;
async function getDriverInfo(driver) {
    return { environment: driver.environment };
}
exports.getDriverInfo = getDriverInfo;
async function getWindowSize(driver) {
    return utils.geometry.size(await driver.getWindowRect());
}
exports.getWindowSize = getWindowSize;
async function setWindowSize(driver, size) {
    await driver.setWindowRect(size);
}
exports.setWindowSize = setWindowSize;
async function getOrientation(_driver) {
    return 'portrait';
}
exports.getOrientation = getOrientation;
async function getUrl(driver) {
    if (driver._isNative)
        return '';
    return driver.getUrl();
}
exports.getUrl = getUrl;
async function getTitle(driver) {
    if (driver._isNative)
        return '';
    return driver.getTitle();
}
exports.getTitle = getTitle;
async function visit(driver, url) {
    await driver.visit(url);
}
exports.visit = visit;
async function getCurrentWorld(driver) {
    return driver.getCurrentWorld();
}
exports.getCurrentWorld = getCurrentWorld;
async function getElementRegion(_driver, element) {
    return element.region;
}
exports.getElementRegion = getElementRegion;
async function getElementAttribute(_driver, element, attr) {
    return element.attrs[attr];
}
exports.getElementAttribute = getElementAttribute;
async function performAction(_driver, _steps) {
    return;
}
exports.performAction = performAction;
