#!/usr/bin/env python3
"""Context-aware help — shows what's relevant RIGHT NOW, not everything."""

import sys, os

sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
from muxlib import run_stdout, B, D, R, CYAN, YELLOW

def main():
    pane_count = int(run_stdout("tmux list-panes | wc -l").strip() or "1")
    pane_cmd = run_stdout("tmux display-message -p '#{pane_current_command}'")
    session = run_stdout("tmux display-message -p '#{session_name}'")
    win_count = int(run_stdout(f"tmux list-windows -t '={session}' | wc -l").strip() or "1")
    win_idx = run_stdout("tmux display-message -p '#{window_index}'")
    win_name = run_stdout("tmux display-message -p '#{window_name}'")
    is_shell = pane_cmd in ("zsh", "bash", "sh", "fish", "login")

    print()
    print(f"  {B}{session}{R} > {win_name} (win {win_idx}/{win_count})")
    print()

    if pane_count > 1:
        print(f"  {YELLOW}! Split screen active{R}")
        print(f"    Type {B}exit{R} in the pane you don't need")
        print()

    if not is_shell:
        print(f"  {CYAN}Claude is running here.{R}")
        print(f"    F3 = quick shell    F2 = dashboard")
        print(f"    {D}Opt-B / Opt-F  word back / forward{R}")
        print(f"    {D}Ctrl-A/E line start/end · Ctrl-W del{R}")
        print(f"    {D}Shift-Enter newline · ↑↓ history{R}")
        print()
    else:
        print(f"  {D}Shell window.{R}")
        print(f"    {B}claude{R} to start    {B}mux new \"task\"{R} for new window")
        print()

    if win_count > 1:
        print(f"  {D}{win_count} windows — Ctrl-Space 1/2/3 to switch{R}")
        print()

    print(f"  {B}Keys:{R}")
    print(f"    F1 Help    F2 Dashboard    F3 Shell")
    print(f"    F4 Trail   F5 Sessions")
    print(f"    Ctrl-Space d Detach  s Pick desk")
    print(f"    Ctrl-Space [ scroll back   q = live")
    print(f"    drag = copy   Y = copy w/o wraps")
    print()
    print(f"  {D}Full list: mux help{R}")
    print(f"  {D}q = close{R}")
    print()

if __name__ == "__main__":
    main()
