"""Concrete component implementations.

Loaded from components.yaml via ComponentRegistry.load_components_yaml().
Manual imports are no longer needed — add new impls to components.yaml.

Classes are still importable from this package via lazy __getattr__.
"""

from kernbench.components.base import ComponentRegistry

ComponentRegistry.load_components_yaml()

# Lazy re-export: allow `from kernbench.components.builtin import FooComponent`
# without eagerly importing every module.
_CLASS_MAP: dict[str, str] = {}  # ClassName → "module.path:ClassName"


def _build_class_map() -> None:
    if _CLASS_MAP:
        return
    for class_path in ComponentRegistry._lazy.values():
        module_path, class_name = class_path.rsplit(":", 1)
        _CLASS_MAP[class_name] = class_path


def __getattr__(name: str):
    _build_class_map()
    class_path = _CLASS_MAP.get(name)
    if class_path is None:
        raise ImportError(f"cannot import name '{name}' from 'kernbench.components.builtin'")
    import importlib
    module_path, class_name = class_path.rsplit(":", 1)
    mod = importlib.import_module(module_path)
    return getattr(mod, class_name)
