"""Help screen overlay for Ghostty Settings TUI."""

from textual.app import ComposeResult
from textual.binding import Binding
from textual.containers import Vertical
from textual.screen import ModalScreen
from textual.widgets import Static


HELP_TEXT = """
[bold #ff79c6]Ghostty Settings TUI[/bold #ff79c6]
[#f8f8f2]A terminal UI for managing Ghostty configuration[/#f8f8f2]

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

[bold #bd93f9]Navigation[/bold #bd93f9]
  [#8be9fd]Tab[/#8be9fd] / [#8be9fd]Shift+Tab[/#8be9fd]    Move between widgets
  [#8be9fd]↑[/#8be9fd] / [#8be9fd]↓[/#8be9fd]              Navigate options/categories
  [#8be9fd]→[/#8be9fd] / [#8be9fd]Enter[/#8be9fd]          Select category
  [#8be9fd]Escape[/#8be9fd]             Back to category list

[bold #bd93f9]Actions[/bold #bd93f9]
  [#8be9fd]Ctrl+S[/#8be9fd]             Save configuration
  [#8be9fd]?[/#8be9fd]                  Toggle this help
  [#8be9fd]Ctrl+Q[/#8be9fd]             Quit application

[bold #bd93f9]Editing[/bold #bd93f9]
  [#f8f8f2]• Boolean options: Click or press Enter to toggle[/#f8f8f2]
  [#f8f8f2]• String/Number options: Type to edit, Enter to confirm[/#f8f8f2]
  [#f8f8f2]• Enum options: Select from dropdown list[/#f8f8f2]

[bold #bd93f9]Indicators[/bold #bd93f9]
  [#ffb86c]●[/#ffb86c] [#f8f8f2]Modified option (unsaved change)[/#f8f8f2]

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

[#6272a4]Configuration file: ~/.config/ghostty/config[/#6272a4]
[#6272a4]Ghostty documentation: https://ghostty.org/docs[/#6272a4]

[#f8f8f2]Press [/#f8f8f2][#8be9fd]Escape[/#8be9fd][#f8f8f2] or [/#f8f8f2][#8be9fd]?[/#8be9fd][#f8f8f2] to close[/#f8f8f2]
"""


class HelpScreen(ModalScreen[None]):
    """Modal help screen overlay."""

    DEFAULT_CSS = """
    HelpScreen {
        align: center middle;
    }

    HelpScreen > Vertical {
        width: 60;
        height: auto;
        max-height: 80%;
        background: #282a36;
        border: double #bd93f9;
        padding: 1 2;
    }

    HelpScreen #help-content {
        height: auto;
        padding: 1;
    }
    """

    BINDINGS = [
        Binding("escape", "close", "Close"),
        Binding("question_mark", "close", "Close"),
        Binding("q", "close", "Close"),
    ]

    def compose(self) -> ComposeResult:
        """Compose the help screen."""
        with Vertical():
            yield Static(HELP_TEXT, id="help-content")

    def action_close(self) -> None:
        """Close the help screen."""
        self.dismiss()
