"""Behave steps for TUI prompt symbol handling."""

from __future__ import annotations

from behave import given, then, when
from behave.runner import Context

from cleveragents.tui.widgets.prompt import PromptInput


@given("a TUI prompt widget")
def step_create_prompt(context: Context) -> None:
    context.tui_prompt = PromptInput(
        placeholder="Type message, /command, or !shell ..."
    )


@when('I set the TUI prompt value to "{value}"')
def step_set_prompt_value(context: Context, value: str) -> None:
    context.tui_prompt.value = value


@when("I set the TUI prompt value to")
def step_set_prompt_value_block(context: Context) -> None:
    assert context.text is not None
    context.tui_prompt.value = context.text


@then('the TUI prompt symbol should be "{symbol}"')
def step_assert_prompt_symbol(context: Context, symbol: str) -> None:
    assert context.tui_prompt.prompt_symbol == symbol


@when("I consume the TUI prompt text")
def step_consume_prompt_text(context: Context) -> None:
    context.tui_consumed_prompt = context.tui_prompt.consume_text()


@then('the consumed TUI prompt text should be "{value}"')
def step_assert_consumed_text(context: Context, value: str) -> None:
    assert context.tui_consumed_prompt.text == value
