"""Prompt widget and submitted message event."""

from __future__ import annotations

import importlib
from dataclasses import dataclass
from typing import Any


def _load_input_base() -> type[Any]:
    try:
        return importlib.import_module("textual.widgets").Input
    except Exception:  # pragma: no cover

        class _FallbackInput:
            value = ""

            def __init__(self, *args: object, **kwargs: object) -> None:
                self.value = ""

        return _FallbackInput


_InputBase = _load_input_base()


@dataclass(slots=True, frozen=True)
class PromptSubmitted:
    """Submitted prompt payload."""

    text: str


class PromptInput(_InputBase):
    """Input widget wrapper with helper methods."""

    def consume_text(self) -> PromptSubmitted:
        text = self.value
        self.value = ""
        return PromptSubmitted(text=text)
