"""Prompt customization command."""

from mudlib.player import Player
from mudlib.prompt import DEFAULT_TEMPLATES


async def cmd_prompt(player: Player, args: str) -> None:
    """View or customize the player's prompt.

    With no arguments, shows the current template and available variables.
    With a template string, sets the player's custom prompt.
    With 'reset', clears the custom template back to mode default.
    """
    args = args.strip()

    if not args:
        # Show current template and available variables
        current = player.prompt_template or DEFAULT_TEMPLATES.get(
            player.mode, "{stamina_gauge} {pl} > "
        )
        msg = f"Current prompt: {current}\r\n\r\n"
        msg += "Available variables:\r\n"
        msg += "  stamina_pct - stamina percentage (0-100)\r\n"
        msg += "  stamina - current stamina value\r\n"
        msg += "  max_stamina - maximum stamina\r\n"
        msg += "  stamina_gauge - colored stamina percentage\r\n"
        msg += "  pl - current power level\r\n"
        msg += "  max_pl - maximum power level\r\n"
        msg += "  name - your character name\r\n"
        msg += "  mode - current mode (normal, combat, etc)\r\n"
        msg += "  x, y - coordinates\r\n"
        msg += "  opponent - combat opponent name\r\n"
        msg += "  move - current attack/defense move\r\n"
        msg += "  combat_state - combat state (idle/fighting)\r\n"
        msg += "\r\n"
        msg += "Examples:\r\n"
        msg += "  prompt {stamina_gauge} {pl} >           (simple, default)\r\n"
        msg += "  prompt {stamina_gauge} {pl}/{max_pl} [{name}] >  (full)\r\n"
        msg += "  prompt reset                            (back to default)\r\n"
        await player.send(msg)
        return

    if args.lower() == "reset":
        # Clear custom template
        player.prompt_template = None
        await player.send("Prompt reset to default.\r\n")
        return

    # Set custom template
    player.prompt_template = args
    await player.send(f"Prompt set to: {args}\r\n")
