from __future__ import annotations

from textual.app import ComposeResult
from textual.reactive import reactive
from textual.widget import Widget
from textual.widgets import Static


class TerminalView(Widget):
    """Panel showing terminal screen content from a workspace/surface."""

    content: reactive[str] = reactive("", always_update=True)
    header_text: reactive[str] = reactive("Terminal Preview")

    def compose(self) -> ComposeResult:
        yield Static("", id="term-header")
        yield Static("", id="term-content", markup=False)

    def watch_header_text(self, value: str) -> None:
        try:
            self.query_one("#term-header", Static).update(
                f"[bold]{value}[/]"
            )
        except Exception:
            pass

    def watch_content(self, value: str) -> None:
        try:
            self.query_one("#term-content", Static).update(value)
        except Exception:
            pass
