import logging
import os
from pathlib import Path
from typing import Optional


_logger = logging.getLogger(__name__)

IMAGE_DIR = "Images"
FLOW_PROGRAM_DIRECTORY = os.getenv("FLOW_PROGRAM_DIRECTORY", None)

ENV_EXISTS: bool = FLOW_PROGRAM_DIRECTORY is not None

if not ENV_EXISTS:
    _logger.warning("Unable to find FLOW_PROGRAM_DIRECTORY environment variable. Icons will not be loaded.")


def _get_icon(icon_name: str, file_ext: str = "png") -> Optional[str]:
    if ENV_EXISTS:
        return str(Path(FLOW_PROGRAM_DIRECTORY) / IMAGE_DIR / f"{icon_name}.{file_ext}")  # type: ignore
    return None


ADMIN = _get_icon("admin")
APP = _get_icon("app")
APP_ERROR = _get_icon("app_error")
APP_MISSING_IMG = _get_icon("app_missing_img")
BAIDU = _get_icon("baidu")
BING = _get_icon("bing")
BOOKMARK = _get_icon("bookmark")
BROWSER = _get_icon("Browser")
CALCULATOR = _get_icon("calculator")
CANCEL = _get_icon("cancel")
CHECKUPDATE = _get_icon("checkupdate")
CLOSE = _get_icon("close")
CMD = _get_icon("cmd")
COLOR = _get_icon("color")
CONTEXT_MENU = _get_icon("context_menu")
CONTROLPANEL_SMALL = _get_icon("ControlPanel_Small")
COPY = _get_icon("copy")
COPYLINK = _get_icon("copylink")
DELETEDFOLDER = _get_icon("deletedfolder")
DISABLE = _get_icon("disable")
DOWN = _get_icon("down")
DUCKDUCKGO = _get_icon("duckduckgo")
ERROR = _get_icon("error")
EVERYTHING_ERROR = _get_icon("everything_error")
EXCLUDEINDEXPATH = _get_icon("excludeindexpath")
EXE = _get_icon("EXE")
EXPLORER = _get_icon("explorer")
FACEBOOK = _get_icon("facebook")
FILE = _get_icon("file")
FIND = _get_icon("find")
FOLDER = _get_icon("folder")
GAMEMODE = _get_icon("gamemode")
GIST = _get_icon("gist")
GITHUB = _get_icon("github")
GMAIL = _get_icon("gmail")
GOOGLE = _get_icon("google")
GOOGLE_DRIVE = _get_icon("google_drive")
GOOGLE_MAPS = _get_icon("google_maps")
GOOGLE_TRANSLATE = _get_icon("google_translate")
HIBERNATE = _get_icon("hibernate")
HISTORY = _get_icon("history")
IMAGE = _get_icon("image")
INDEX_ERROR = _get_icon("index_error")
INDEX_ERROR2 = _get_icon("index_error2")
INDEXOPTION = _get_icon("indexoption")
LINK = _get_icon("link")
LOADING = _get_icon("loading")
LOCK = _get_icon("lock")
LOGOFF = _get_icon("logoff")
MANIFESTSITE = _get_icon("manifestsite")
NETFLIX = _get_icon("netflix")
NEW_MESSAGE = _get_icon("New Message")
OK = _get_icon("ok")
OPEN = _get_icon("open")
OPENRECYCLEBIN = _get_icon("openrecyclebin")
PICTURES = _get_icon("pictures")
PLUGINSMANAGER = _get_icon("pluginsmanager")
PROGRAM = _get_icon("program")
QUICKACCESS = _get_icon("quickaccess")
RECYCLEBIN = _get_icon("recyclebin")
REMOVEQUICKACCESS = _get_icon("removequickaccess")
REQUEST = _get_icon("request")
RESTART = _get_icon("restart")
RESTART_ADVANCED = _get_icon("restart_advanced")
ROBOT_ERROR = _get_icon("robot_error")
SEARCH = _get_icon("search")
SETTINGS = _get_icon("settings")
SHELL = _get_icon("shell")
SHUTDOWN = _get_icon("shutdown")
SLEEP = _get_icon("sleep")
SOURCECODE = _get_icon("sourcecode")
STACKOVERFLOW = _get_icon("stackoverflow")
TWITTER = _get_icon("twitter")
UP = _get_icon("up")
UPDATE = _get_icon("update")
URL = _get_icon("url")
USER = _get_icon("user")
WARNING = _get_icon("warning")
WEB_SEARCH = _get_icon("web_search")
WIKI = _get_icon("wiki")
WINDOWSINDEXINGOPTIONS = _get_icon("windowsindexingoptions")
WINDOWSSETTINGSLIGHT = _get_icon("windowssettings.light")
WIZARD = _get_icon("wizard")
WOLFRAMALPHA = _get_icon("wolframalpha")
WORK = _get_icon("work")
YAHOO = _get_icon("yahoo")
YOUTUBE = _get_icon("youtube")
YOUTUBEMUSIC = _get_icon("youtubemusic")
