"""Shell detector with fish focus."""

from ..models import Context
from .state import DetectionState


def detect_shell(state: DetectionState) -> Context | None:
    """Detect shell at prompt (fish, bash, zsh, etc).

    Triggers when the pane's current command is a shell,
    meaning we're at a shell prompt with no other program running.

    Args:
        state: Detection state with environment

    Returns:
        Shell context if detected
    """
    # Check pane command - this is what's currently running
    pane_command = state.get("pane_command")
    if not pane_command:
        return None

    pane_command = pane_command.lower()

    # List of shells we want to detect
    shells = ["fish", "bash", "zsh", "sh", "ksh", "tcsh"]

    if any(shell == pane_command for shell in shells):
        # Determine which shell for metadata
        shell_name = pane_command
        is_fish = shell_name == "fish"

        return Context(
            name="shell",
            type="shell",
            priority=1,  # Higher than tmux (0), lower than editors (2+)
            sheet="shell",  # Points to shell.yaml
            metadata={
                "shell_type": shell_name,
                "is_fish": is_fish,
                "detected_from": "pane_command",
                "user_shell": state.env.shell,
            },
        )

    return None
