from __future__ import annotations

from textual.app import ComposeResult
from textual.widget import Widget
from textual.widgets import RichLog


class ActivityFeed(Widget):
    """Live feed of agent activity across all workspaces."""

    def compose(self) -> ComposeResult:
        yield RichLog(id="activity-log", highlight=True, markup=True, wrap=True)

    def add_entry(self, workspace_name: str, text: str, style: str = "") -> None:
        log = self.query_one("#activity-log", RichLog)
        prefix = f"[bold]{workspace_name}[/]"
        if style:
            log.write(f"{prefix}: [{style}]{text}[/]")
        else:
            log.write(f"{prefix}: {text}")

    def add_system(self, text: str) -> None:
        log = self.query_one("#activity-log", RichLog)
        log.write(f"[dim italic]{text}[/]")
