"""Classroom demonstration. This is not an additional Lab08 assignment."""
from pathlib import Path
import sys


def count_extensions(names: list[str]) -> dict[str, int]:
    """Count final suffixes, ignoring case; keep names unchanged.

    Input: nonempty basenames. An empty list is allowed.
    No suffix, a lone leading-dot name, or a trailing dot counts as '(none)'.
    """
    counts = {}
    for name in names:
        parts = name.rsplit(".", 1)
        ext = "(none)"
        if len(parts) == 2 and parts[0] and parts[1]:
            ext = parts[1].lower()
        counts[ext] = counts.get(ext, 0) + 1
    return counts


def main() -> None:
    """Instructor-provided file and command-line adapter; see Lecture 12."""
    folder = Path(sys.argv[1]) if len(sys.argv) > 1 else Path("sample-files")
    names = [item.name for item in folder.rglob("*") if item.is_file()]
    counts = count_extensions(names)
    for ext in sorted(counts):
        print(f"{ext}: {counts[ext]}")


if __name__ == "__main__":
    main()
