/**
 * TUI config selector for `pi config` command
 */
import { ConfigSelectorComponent } from '../shell/components/selectors/config-selector.js';
import { initTheme, stopThemeWatcher } from '../shell/theme/runtime.js';
import { ProcessTerminal, TUI } from '../tui/index.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({ useAlternateBuffer: true }));
        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.addChild(selector);
        ui.setFocus(selector.getResourceList());
        ui.start();
    });
}
//# sourceMappingURL=config-selector.js.map