"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.checkChromeCompatibility = checkChromeCompatibility;
const playwright_core_1 = require("playwright-core");
const chromeFinder_1 = require("../browserEngines/chromeFinder");
const loggingProvider_1 = require("../providers/logging/loggingProvider");
const chalk = require('chalk');
const MIN_CHROME_MAJOR_VERSION = 146;
async function checkChromeCompatibility() {
    process.stdout.write(' Checking browser compatibility...\n');
    try {
        const chromePath = (0, chromeFinder_1.searchForChrome)();
        if (!chromePath) {
            process.stdout.write(chalk.yellow(` Warning: no stable Google Chrome installation was found on this system.\n` +
                ` Chrome ${MIN_CHROME_MAJOR_VERSION} or newer is required for mabl debug sessions.\n`));
            return;
        }
        const browser = await playwright_core_1.chromium.launch({
            executablePath: chromePath,
            headless: true,
        });
        let versionString;
        try {
            versionString = browser.version();
        }
        finally {
            await browser.close();
        }
        const major = parseInt(versionString.split('.')[0], 10);
        if (Number.isNaN(major) || major < MIN_CHROME_MAJOR_VERSION) {
            process.stdout.write(chalk.yellow(` Warning: Chrome ${versionString} is older than the supported minimum.\n` +
                ` Update Chrome to ${MIN_CHROME_MAJOR_VERSION} or newer for mabl debug sessions.\n`));
            return;
        }
        process.stdout.write(chalk.green(` Chrome ${versionString} detected.\n`));
    }
    catch (err) {
        loggingProvider_1.logger.debug(`Chrome compatibility check failed: ${String(err)}`);
    }
}
