from typing import Self

from htmlnode import HtmlNode


class LeafNode(HtmlNode):
    def __init__(
        self: Self,
        tag: str | None,
        value: str | None,
        props: dict | None = None,
    ) -> None:
        super().__init__(tag, value, [], props)

    def to_html(self: Self) -> str:
        if self.value is None:
            raise ValueError

        if self.tag is None:
            return self.value

        return f"<{self.tag}{self.props_to_html()}>{self.value}</{self.tag}>"

    def __repr__(self: Self) -> str:
        return f"{LeafNode.__name__}({self.tag}, {self.value}, {self.props})"
