/**
 * TUI config selector for `pi config` command
 */
import { ProcessTerminal, TUI } from "@earendil-works/pi-tui";
import { ConfigSelectorComponent } from "../modes/interactive/components/config-selector.js";
import { initTheme, stopThemeWatcher } from "../modes/interactive/theme/theme.js";
/** Show TUI config selector and return when closed */
export async function selectConfig(options) {
    // Initialize theme before showing TUI
    initTheme(options.settingsManager.getTheme(), true);
    return new Promise((resolve) => {
        const ui = new TUI(new ProcessTerminal());
        let resolved = false;
        const selector = new ConfigSelectorComponent(options.resolvedPaths, options.settingsManager, options.cwd, options.agentDir, () => {
            if (!resolved) {
                resolved = true;
                ui.stop();
                stopThemeWatcher();
                resolve();
            }
        }, () => {
            ui.stop();
            stopThemeWatcher();
            process.exit(0);
        }, () => ui.requestRender(), ui.terminal.rows);
        ui.addChild(selector);
        ui.setFocus(selector.getResourceList());
        ui.start();
    });
}
//# sourceMappingURL=config-selector.js.map