from __future__ import annotations

from kagan.keybindings.registry import KeyBindingDef

KANBAN_BINDINGS: list[KeyBindingDef] = [
    # Global
    KeyBindingDef(
        "q",
        "quit",
        "Quit",
        "global",
        priority=True,
        help_text="Quit application",
    ),
    # Primary actions
    KeyBindingDef(
        "n",
        "new_ticket",
        "New",
        "primary",
        help_text="Create new ticket",
    ),
    KeyBindingDef(
        "v",
        "view_details",
        "View",
        "primary",
        help_text="View ticket details",
    ),
    KeyBindingDef(
        "e",
        "edit_ticket",
        "Edit",
        "primary",
        help_text="Edit selected ticket",
    ),
    KeyBindingDef(
        "enter",
        "open_session",
        "Open",
        "primary",
        help_text="Open session (PAIR: tmux, AUTO: agent output)",
    ),
    KeyBindingDef(
        "g",
        "activate_leader",
        "Go...",
        "primary",
        help_text="Leader key for compound commands",
    ),
    KeyBindingDef(
        "slash",
        "toggle_search",
        "Search",
        "primary",
        key_display="/",
        help_text="Toggle search bar",
    ),
    KeyBindingDef(
        "p",
        "open_planner",
        "Plan Mode",
        "primary",
        help_text="Switch to Plan mode",
    ),
    KeyBindingDef(
        "comma",
        "open_settings",
        "Settings",
        "primary",
        key_display=",",
        help_text="Open settings",
    ),
    KeyBindingDef(
        "x",
        "delete_ticket_direct",
        "Delete",
        "primary",
        help_text="Delete ticket",
    ),
    KeyBindingDef(
        "y",
        "duplicate_ticket",
        "Yank",
        "primary",
        show_in_footer=False,
        help_text="Duplicate (yank) ticket",
    ),
    KeyBindingDef(
        "c",
        "copy_ticket_id",
        "Copy ID",
        "primary",
        show_in_footer=False,
        help_text="Copy ticket ID to clipboard",
    ),
    # Navigation - vim style (grouped for help display)
    KeyBindingDef(
        "h",
        "focus_left",
        "Left",
        "navigation",
        show_in_footer=False,
        help_text="Move focus to left column",
        help_group="vim_horizontal",
    ),
    KeyBindingDef(
        "j",
        "focus_down",
        "Down",
        "navigation",
        show_in_footer=False,
        help_text="Move focus down in column",
        help_group="vim_vertical",
    ),
    KeyBindingDef(
        "k",
        "focus_up",
        "Up",
        "navigation",
        show_in_footer=False,
        help_text="Move focus up in column",
        help_group="vim_vertical",
    ),
    KeyBindingDef(
        "l",
        "focus_right",
        "Right",
        "navigation",
        show_in_footer=False,
        help_text="Move focus to right column",
        help_group="vim_horizontal",
    ),
    # Navigation - arrow keys (grouped with vim equivalents)
    KeyBindingDef(
        "left",
        "focus_left",
        "Left",
        "navigation",
        show_in_footer=False,
        help_group="vim_horizontal",
    ),
    KeyBindingDef(
        "right",
        "focus_right",
        "Right",
        "navigation",
        show_in_footer=False,
        help_group="vim_horizontal",
    ),
    KeyBindingDef(
        "down",
        "focus_down",
        "Down",
        "navigation",
        show_in_footer=False,
        help_group="vim_vertical",
    ),
    KeyBindingDef(
        "up",
        "focus_up",
        "Up",
        "navigation",
        show_in_footer=False,
        help_group="vim_vertical",
    ),
    # Navigation - tab
    KeyBindingDef(
        "tab",
        "focus_next_column",
        "Next Column",
        "navigation",
        show_in_footer=False,
        help_text="Cycle to next column",
    ),
    KeyBindingDef(
        "shift+tab",
        "focus_prev_column",
        "Prev Column",
        "navigation",
        show_in_footer=False,
        help_text="Cycle to previous column",
    ),
    # Context-specific actions
    KeyBindingDef(
        "a",
        "start_agent",
        "Start agent",
        "context",
        context="AUTO tickets",
        help_text="Start agent manually",
    ),
    KeyBindingDef(
        "s",
        "stop_agent",
        "Stop agent",
        "context",
        context="AUTO tickets",
        help_text="Stop agent and move to backlog",
    ),
    KeyBindingDef(
        "w",
        "watch_agent",
        "Watch agent",
        "context",
        show_in_footer=False,
        context="AUTO tickets",
        help_text="Watch agent output",
    ),
    KeyBindingDef(
        "D",
        "view_diff",
        "Diff",
        "context",
        show_in_footer=False,
        context="REVIEW tickets",
        help_text="View diff",
    ),
    KeyBindingDef(
        "r",
        "open_review",
        "Review",
        "context",
        show_in_footer=False,
        context="REVIEW tickets",
        help_text="Open review modal",
    ),
    KeyBindingDef(
        "m",
        "merge_direct",
        "Merge",
        "context",
        context="REVIEW tickets",
        help_text="Merge and complete",
    ),
    # Utility (no help display)
    KeyBindingDef("escape", "deselect", "", "utility", show_in_footer=False),
    KeyBindingDef("ctrl+c", "interrupt", "", "utility", show_in_footer=False),
]

# Leader key bindings (g+key sequences) - conceptual, for help generation
KANBAN_LEADER_BINDINGS: list[KeyBindingDef] = [
    KeyBindingDef(
        "h",
        "move_backward",
        "Move←",
        "leader",
        leader_sequence=True,
        help_text="Move ticket left (backward in workflow)",
    ),
    KeyBindingDef(
        "l",
        "move_forward",
        "Move→",
        "leader",
        leader_sequence=True,
        help_text="Move ticket right (forward in workflow)",
    ),
    KeyBindingDef(
        "d",
        "view_diff",
        "Diff",
        "leader",
        leader_sequence=True,
        context="REVIEW tickets",
        help_text="View diff",
    ),
    KeyBindingDef(
        "r",
        "open_review",
        "Review",
        "leader",
        leader_sequence=True,
        context="REVIEW tickets",
        help_text="Open review modal",
    ),
    KeyBindingDef(
        "w",
        "watch_agent",
        "Watch",
        "leader",
        leader_sequence=True,
        context="AUTO tickets",
        help_text="Watch agent output",
    ),
]
