import { render } from 'ink';
import { App } from './app.js';
import type { AppState } from './app.js';

export type AppCommand = 'generate' | 'init' | 'select';

export interface RenderArgs {
    command: AppCommand;
    configPath?: string;
    autoConfirm?: boolean;
}

export function renderApp(args: RenderArgs) {
    let initial: AppState;

    if (args.command === 'select') {
        initial = { phase: 'select' };
    } else if (args.command === 'generate') {
        initial = {
            phase: 'generate',
            configPath: args.configPath,
            autoConfirm: args.autoConfirm,
        };
    } else {
        initial = { phase: 'init', afterInit: 'exit' };
    }

    return render(<App initial={initial} />);
}
