"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;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.makeCheck = void 0;
const driver_1 = require("@applitools/driver");
const utils = __importStar(require("@applitools/utils"));
const lang = __importStar(require("./lang"));
const chalk_1 = __importDefault(require("chalk"));
function makeCheck({ type: defaultType = 'classic', eyes, target: defaultTarget, spec, logger: mainLogger, }) {
    let stepIndex = 0;
    return async function check({ type = defaultType, target = defaultTarget, settings, config, logger = mainLogger, } = {}) {
        var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
        var _q, _r, _s, _t;
        logger = logger.extend(mainLogger, { tags: [`check-${type}-${utils.general.shortid()}`] });
        settings = { ...config === null || config === void 0 ? void 0 : config.screenshot, ...config === null || config === void 0 ? void 0 : config.check, ...settings };
        (_a = settings.fully) !== null && _a !== void 0 ? _a : (settings.fully = !settings.region && (!settings.frames || settings.frames.length === 0));
        (_b = settings.waitBeforeCapture) !== null && _b !== void 0 ? _b : (settings.waitBeforeCapture = 100);
        (_c = settings.hideScrollbars) !== null && _c !== void 0 ? _c : (settings.hideScrollbars = true);
        (_d = settings.hideCaret) !== null && _d !== void 0 ? _d : (settings.hideCaret = true);
        settings.overlap = { top: 10, bottom: 50, ...settings === null || settings === void 0 ? void 0 : settings.overlap };
        (_e = settings.matchLevel) !== null && _e !== void 0 ? _e : (settings.matchLevel = 'Strict');
        (_f = settings.ignoreCaret) !== null && _f !== void 0 ? _f : (settings.ignoreCaret = true);
        (_g = settings.sendDom) !== null && _g !== void 0 ? _g : (settings.sendDom = eyes.test.account.rcaEnabled || settings.matchLevel === 'Layout' || settings.enablePatterns || settings.useDom);
        (_h = settings.autProxy) !== null && _h !== void 0 ? _h : (settings.autProxy = eyes.test.eyesServer.proxy);
        (_j = settings.useDom) !== null && _j !== void 0 ? _j : (settings.useDom = false);
        (_k = (_q = settings).retryTimeout) !== null && _k !== void 0 ? _k : (_q.retryTimeout = 2000);
        settings.lazyLoad = settings.lazyLoad === true ? {} : settings.lazyLoad;
        if (settings.lazyLoad) {
            (_l = (_r = settings.lazyLoad).scrollLength) !== null && _l !== void 0 ? _l : (_r.scrollLength = 300);
            (_m = (_s = settings.lazyLoad).waitingTime) !== null && _m !== void 0 ? _m : (_s.waitingTime = 2000);
            (_o = (_t = settings.lazyLoad).maxAmountToScroll) !== null && _o !== void 0 ? _o : (_t.maxAmountToScroll = 15000);
        }
        settings.stepIndex = stepIndex++;
        (_p = settings.waitBetweenStitches) !== null && _p !== void 0 ? _p : (settings.waitBetweenStitches = utils.types.isObject(settings.lazyLoad) ? settings.lazyLoad.waitingTime : 100);
        if (settings.matchLevel === 'Content') {
            logger.console.log(chalk_1.default.yellow(lang.matchLevelContentDeprecatedWarning));
        }
        const driver = (0, driver_1.isDriver)(target, spec)
            ? await (0, driver_1.makeDriver)({ spec, driver: target, reset: target === defaultTarget, logger })
            : null;
        const typedEyes = await eyes.getTypedEyes({ type, logger });
        return typedEyes.check({ target: driver !== null && driver !== void 0 ? driver : target, settings, logger });
    };
}
exports.makeCheck = makeCheck;
