/**
 * Resolves the Chromium/Chrome executable path on the current machine.
 *
 * Priority:
 *  1. $AVIS_CHROMIUM env var
 *  2. system Chromium.app (macOS)
 *  3. system Google Chrome.app (macOS)
 *  4. chromium / google-chrome on PATH (Linux)
 *  5. undefined -> caller can fall back to bundled Playwright browser
 */
import { execSync } from "node:child_process";
import { existsSync } from "node:fs";
const MAC_CANDIDATES = [
    "/Applications/Chromium.app/Contents/MacOS/Chromium",
    "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome",
    "/Applications/Google Chrome Canary.app/Contents/MacOS/Google Chrome Canary",
];
const LINUX_CANDIDATES = [
    "/usr/bin/chromium",
    "/usr/bin/chromium-browser",
    "/usr/bin/google-chrome",
    "/usr/bin/google-chrome-stable",
];
export function resolveChromiumPath() {
    const fromEnv = process.env.AVIS_CHROMIUM;
    if (fromEnv && existsSync(fromEnv))
        return fromEnv;
    const candidates = process.platform === "darwin" ? MAC_CANDIDATES : LINUX_CANDIDATES;
    for (const candidate of candidates) {
        if (existsSync(candidate))
            return candidate;
    }
    // Last resort: probe PATH
    try {
        const out = execSync("command -v chromium || command -v google-chrome || command -v chrome", {
            encoding: "utf-8",
            stdio: ["pipe", "pipe", "ignore"],
        }).trim();
        if (out && existsSync(out))
            return out;
    }
    catch {
        // ignore
    }
    return undefined;
}
//# sourceMappingURL=chromium-resolver.js.map