"""Helper script for dumping Tabler icon names into a Literal type."""

from pathlib import Path

HERE_DIR = Path(__file__).absolute().parent
ICON_DIR = HERE_DIR / "_icons"


def enum_name_from_icon(name: str) -> str:
    """Capitalize an icon name for use as an enum name."""
    name = name.upper()
    name = name.replace("-", "_")
    if name[0].isdigit():
        name = "ICON_" + name
    return name


if __name__ == "__main__":
    icon_names = sorted([path.stem for path in ICON_DIR.glob("*.svg")])

    (HERE_DIR / "_icons_enum.py").write_text(
        "\n".join(
            [
                "# Automatically generated by `_icons_generate_enum.py`",
                "# See https://tabler-icons.io/",
                "",
                "import enum",
                "",
                "class Icon(enum.Enum):",
            ]
            + [
                # Prefix all icon names with ICON_, since some of them start with
                # numbers and can't directly be used as Python names.
                f'    {enum_name_from_icon(icon)} = "{icon}"'
                for icon in icon_names
            ]
        )
    )
