export class DevTUI {
    options;
    app = null;
    updateStatusFn = null;
    updateAppPortFn = null;
    updateUpdateInfoFn = null;
    updateUseHttpsFn = null;
    constructor(options) {
        this.options = options;
    }
    async start() {
        // Clear screen and scrollback before starting TUI
        process.stdout.write("\x1b[2J\x1b[H\x1b[3J");
        // 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;
        try {
            // Choose TUI implementation based on platform
            // OpenTUI has native bindings only available on macOS, use Ink-based TUI elsewhere
            // Use explicit string paths (not variables) so bun compile can statically analyze the imports
            const mod = process.platform === "darwin"
                ? await import("./tui-interface-opentui.js")
                : await import("./tui-interface-impl.js");
            const { app, updateStatus, updateAppPort, updateUpdateInfo, updateUseHttps } = await mod.runTUI(this.options);
            this.app = app;
            this.updateStatusFn = updateStatus;
            this.updateAppPortFn = updateAppPort;
            this.updateUpdateInfoFn = updateUpdateInfo;
            this.updateUseHttpsFn = updateUseHttps;
        }
        catch (error) {
            console.error("Failed to start TUI:", error);
            throw error;
        }
        // Restore original error logging after startup
        setTimeout(() => {
            console.error = originalError;
        }, 1000);
    }
    updateStatus(status) {
        if (this.updateStatusFn) {
            this.updateStatusFn(status);
        }
    }
    updateAppPort(port) {
        if (this.updateAppPortFn) {
            this.updateAppPortFn(port);
        }
    }
    updateUpdateInfo(info) {
        if (this.updateUpdateInfoFn) {
            this.updateUpdateInfoFn(info);
        }
    }
    updateUseHttps(useHttps) {
        if (this.updateUseHttpsFn) {
            this.updateUseHttpsFn(useHttps);
        }
    }
    async shutdown() {
        if (this.app) {
            this.app.unmount();
        }
        // Clear screen and scrollback on shutdown
        process.stdout.write("\x1b[2J\x1b[H\x1b[3J");
    }
}
//# sourceMappingURL=tui-interface.js.map