"""Shared context passed to commands and components."""

from __future__ import annotations

from dataclasses import dataclass
from typing import TYPE_CHECKING

if TYPE_CHECKING:
    from clients.terminal.state import StateManager
    from clients.terminal.tui.chat_model import ChatModel
    from clients.terminal.tui.widgets.chat_panel import ChatPanel
    from clients.terminal.tui.widgets.status_panel import StatusPanel
    from clients.terminal.ws_client import NaviWebSocketClient


@dataclass
class TuiContext:
    """Mutable bag of services and widgets available to commands."""

    session_id: str | None = None
    profile_id: str | None = None
    ws_client: "NaviWebSocketClient | None" = None
    state: "StateManager | None" = None
    chat_panel: "ChatPanel | None" = None
    status_panel: "StatusPanel | None" = None
    chat_model: "ChatModel | None" = None

    def app(self):
        """Return the running TuiApp instance."""
        from textual.app import App

        # This is a convenience accessor used by commands that need App-level actions.
        return App.get_active_app()
