import os
import glob
import RNS
import nomadnet

py_modules  = glob.glob(os.path.dirname(__file__)+"/*.py")
pyc_modules = glob.glob(os.path.dirname(__file__)+"/*.pyc")
modules     = py_modules+pyc_modules
__all__ = list(set([os.path.basename(f).replace(".pyc", "").replace(".py", "") for f in modules if not (f.endswith("__init__.py") or f.endswith("__init__.pyc"))]))

THEME_DARK     = 0x01
THEME_LIGHT    = 0x02

UI_NONE       = 0x00
UI_MENU       = 0x01
UI_TEXT       = 0x02
UI_GRAPHICAL  = 0x03
UI_WEB        = 0x04
UI_MODES = [UI_NONE, UI_MENU, UI_TEXT, UI_GRAPHICAL, UI_WEB]

def spawn(uimode):
    if uimode in UI_MODES:
        if uimode == UI_NONE:
            RNS.log("Starting Nomad Network daemon...", RNS.LOG_INFO)
        else:
            RNS.log("Starting user interface...", RNS.LOG_INFO)

        if uimode == UI_MENU:
            from .MenuUI import MenuUI
            return MenuUI()
        elif uimode == UI_TEXT:
            from .TextUI import TextUI
            return TextUI()
        elif uimode == UI_GRAPHICAL:
            from .GraphicalUI import GraphicalUI
            return GraphicalUI()
        elif uimode == UI_WEB:
            from .WebUI import WebUI
            return WebUI()
        elif uimode == UI_NONE:
            from .NoneUI import NoneUI
            return NoneUI()
        else:
            return None
    else:
        RNS.log("Invalid UI mode", RNS.LOG_ERROR, _override_destination=True)
        nomadnet.panic()