/**
 * olam list — List all active worlds.
 */
import pc from 'picocolors';
import { loadContext } from '../context.js';
import { printError, formatAge } from '../output.js';
export function registerList(program) {
    program
        .command('list')
        .alias('ls')
        .description('List active worlds')
        .action(async () => {
        const { ctx, error } = await loadContext();
        if (!ctx) {
            printError(error?.message ?? 'Olam is not configured. Run `olam init` first.');
            process.exitCode = 1;
            return;
        }
        const worlds = ctx.worldManager.listWorlds();
        if (worlds.length === 0) {
            console.log(pc.dim('No worlds. Create one with `olam create --name my-world`.'));
            return;
        }
        console.log(`${pc.bold(String(worlds.length))} world(s)\n`);
        for (const w of worlds) {
            const statusColor = w.status === 'running'
                ? pc.green(w.status)
                : w.status === 'error'
                    ? pc.red(w.status)
                    : pc.yellow(w.status);
            const age = formatAge(w.createdAt);
            const cost = `$${w.totalCostUsd.toFixed(2)}`;
            console.log(`  ${pc.bold(w.name)} ${pc.dim(`(${w.id})`)}`);
            console.log(`    ${statusColor}  ${pc.dim('|')}  ${w.repos.join(', ')}  ${pc.dim('|')}  ${cost}  ${pc.dim('|')}  ${age}`);
            console.log();
        }
    });
}
//# sourceMappingURL=list.js.map