export class DevTUI {
    options;
    app = null;
    updateStatusFn = null;
    updateAppPortFn = null;
    updateUpdateAvailableFn = null;
    constructor(options) {
        this.options = options;
    }
    async start() {
        try {
            // Enter alternate screen buffer immediately to prevent scroll history pollution
            // This must happen before any other output
            // Note: alternate screen buffer starts clean, no need to clear
            process.stdout.write("\x1b[?1049h");
            // Temporarily suppress React hook warnings during TUI startup
            const originalError = console.error;
            const suppressReactHookWarnings = (...args) => {
                const message = args[0];
                if (typeof message === "string" && message.includes("Invalid hook call")) {
                    // Suppress React hook warnings during TUI startup - these are known compatibility issues with React 19 canary + Ink
                    return;
                }
                originalError(...args);
            };
            console.error = suppressReactHookWarnings;
            // Use dynamic import to load the TSX implementation at runtime
            const { runTUI } = await import("./tui-interface-impl.js");
            const { app, updateStatus, updateAppPort, updateUpdateAvailable } = await runTUI(this.options);
            this.app = app;
            this.updateStatusFn = updateStatus;
            this.updateAppPortFn = updateAppPort;
            this.updateUpdateAvailableFn = updateUpdateAvailable;
            // Restore original error logging after startup
            setTimeout(() => {
                console.error = originalError;
            }, 1000);
        }
        catch (error) {
            console.error("Failed to start TUI:", error);
            throw error;
        }
    }
    updateStatus(status) {
        if (this.updateStatusFn) {
            this.updateStatusFn(status);
        }
    }
    updateAppPort(port) {
        if (this.updateAppPortFn) {
            this.updateAppPortFn(port);
        }
    }
    updateUpdateAvailable(info) {
        if (this.updateUpdateAvailableFn) {
            this.updateUpdateAvailableFn(info);
        }
    }
    async shutdown() {
        if (this.app) {
            this.app.unmount();
        }
        // Exit alternate screen buffer to restore previous terminal content
        process.stdout.write("\x1b[?1049l");
    }
}
//# sourceMappingURL=tui-interface.js.map