/**
 * Deterministic pre-flight setup for ShortcutXL — platform dispatcher.
 *
 * Runs before the TUI starts on first install (!isInstalled()).
 * Best-effort: installs what it can, the installation agent handles the rest.
 *
 * macOS, Linux, and Windows have independent flows:
 * - macOS: see mac.ts    (uv → Python → packages → sheet engine)
 * - Linux: see linux.ts  (uv → Python → packages → sheet engine)
 * - Windows: see windows.ts  (Git Bash → pip → Chrome → XLL → Excel)
 *
 * Platform modules are lazy-imported so each platform never loads
 * the others' code (PowerShell/registry on Windows, etc.).
 */
import chalk from 'chalk';
import { log, ok, preflightLog, setCurrentStep } from './utils.js';
// ── Main entry point ────────────────────────────────────────────────────
/**
 * Run deterministic pre-flight checks and auto-install prerequisites.
 * Best-effort — installs what it can, the installation agent handles the rest.
 *
 * Step routing by platform:
 *
 *   Step               macOS    Linux    Windows
 *   ─────────────────  ─────    ─────    ───────
 *   uv (toolchain)       ✓        ✓        –
 *   Python (via uv)      ✓        ✓        –
 *   Packages (via uv)    ✓        ✓        –
 *   Chrome (detect)      ✓        ✓        –
 *   Sheet Engine         ✓        ✓        –
 *   Engine Smoke Test    ✓        ✓        –
 *   Git Bash             –        –        ✓
 *   Python Packages      –        –        ✓
 *   Chrome (install)     –        –        ✓
 *   XLL Registry         –        –        ✓
 *   Launch Excel         –        –        ✓
 *   Connection Test      –        –        ✓
 */
export async function runPreflight() {
    preflightLog.length = 0;
    setCurrentStep('setup');
    console.log();
    console.log(chalk.bold.white('  Setting up ShortcutXL...'));
    console.log(chalk.dim('  ' + '─'.repeat(40)));
    let passed;
    let diagnostics;
    if (process.platform === 'darwin') {
        // ── macOS: uv + Python + headless sheet engine ──
        const mac = await import('./mac.js');
        const uvReady = await mac.ensureUv();
        if (uvReady) {
            const pythonReady = await mac.ensureUvPython();
            if (pythonReady) {
                await mac.ensureUvPackages();
            }
        }
        mac.ensureChromeMac();
        mac.ensureNewSheet();
        passed = mac.smokeTestSheetEngine();
    }
    else if (process.platform === 'linux') {
        // ── Linux: uv + Python + headless sheet engine (same as macOS, different uv target) ──
        const linux = await import('./linux.js');
        const uvReady = await linux.ensureUv();
        if (uvReady) {
            const pythonReady = await linux.ensureUvPython();
            if (pythonReady) {
                await linux.ensureUvPackages();
            }
        }
        linux.ensureChromeLinux();
        linux.ensureNewSheet();
        passed = linux.smokeTestSheetEngine();
    }
    else {
        // ── Windows: Excel + XLL + COM + embedded Python ──
        const win = await import('./windows.js');
        const { collectPreflightDiagnostics } = await import('./diagnostics.js');
        await win.ensureGitBash();
        await win.ensurePipPackages();
        await win.ensureChromeWindows();
        win.ensureXllRegistry();
        await win.ensureExcelAndXll();
        passed = await win.smokeTestExcel();
        if (!passed)
            diagnostics = collectPreflightDiagnostics();
    }
    setCurrentStep('summary');
    console.log();
    passed ? ok('Preflight complete.') : log('Shortcut agent will finish the remaining setup.');
    console.log();
    return { passed, log: [...preflightLog], diagnostics };
}
//# sourceMappingURL=index.js.map