import logging
from importlib.metadata import entry_points

logger = logging.getLogger(__name__)


class Entrypoints:

    def __init__(self):
        self.ui = entry_points(group='elironwars.ui')

    def load_ui(self, ui):
        logger.info('Loading ui %s', ui)
        try:
            ui_class = self.ui[ui].load()
            return ui_class()
        except KeyError:
            logger.critical('Unable to load ui %s', ui)
