"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getBlockedBrowserOverrideWarning = exports.describeDefaultBrowserExposure = exports.describeBrowserPolicy = exports.resolveBrowserExposure = exports.resolveBrowserLaunchFlagResolution = void 0;
const ENABLE_BROWSER_FLAG = '--browser';
const DISABLE_BROWSER_FLAG = '--no-browser';
function resolveBrowserLaunchFlagResolution(args) {
    let override;
    const argsWithoutFlags = [];
    for (let index = 0; index < args.length; index++) {
        const arg = args[index];
        if (arg === '--') {
            argsWithoutFlags.push(...args.slice(index));
            break;
        }
        if (arg === ENABLE_BROWSER_FLAG) {
            if (override === 'force-disable') {
                throw new Error('Use either `--browser` or `--no-browser`, not both.');
            }
            override = 'force-enable';
            continue;
        }
        if (arg === DISABLE_BROWSER_FLAG) {
            if (override === 'force-enable') {
                throw new Error('Use either `--browser` or `--no-browser`, not both.');
            }
            override = 'force-disable';
            continue;
        }
        argsWithoutFlags.push(arg);
    }
    return {
        override,
        argsWithoutFlags,
    };
}
exports.resolveBrowserLaunchFlagResolution = resolveBrowserLaunchFlagResolution;
function resolveBrowserExposure(config, override) {
    const exposeByDefault = config.enabled && config.policy === 'auto';
    const exposeForLaunch = config.enabled &&
        (override === 'force-enable' || (override !== 'force-disable' && exposeByDefault));
    return {
        enabled: config.enabled,
        policy: config.policy,
        override,
        exposeByDefault,
        exposeForLaunch,
    };
}
exports.resolveBrowserExposure = resolveBrowserExposure;
function describeBrowserPolicy(policy) {
    return policy === 'manual' ? 'manual' : 'auto';
}
exports.describeBrowserPolicy = describeBrowserPolicy;
function describeDefaultBrowserExposure(policy) {
    return policy === 'manual' ? 'hidden until `--browser`' : 'auto-exposed';
}
exports.describeDefaultBrowserExposure = describeDefaultBrowserExposure;
function getBlockedBrowserOverrideWarning(laneLabel, exposure) {
    if (exposure.override === 'force-enable' && !exposure.enabled) {
        return `Browser tooling was requested with \`--browser\`, but ${laneLabel} is disabled in CCS config.`;
    }
    return undefined;
}
exports.getBlockedBrowserOverrideWarning = getBlockedBrowserOverrideWarning;
//# sourceMappingURL=browser-policy.js.map