import importlib.metadata

from fastapi.templating import Jinja2Templates

templates = Jinja2Templates(directory="ghostforge/templates")

# Inject version string and Github URL into every template for navbar display.
try:
    gf_version = importlib.metadata.version(__package__)
except ValueError:
    gf_version = "Local"
templates.env.globals["gf_version"] = f"v{gf_version}"
templates.env.globals["gf_repository_url"] = "https://github.com/DarrylNixon/ghostforge"

# Same, but build the navbar from an ordered dictionary for centralization.
# Since 3.7 (we require >= 3.9), dicts are guaranteed ordered as inserted.
templates.env.globals["gf_navbar"] = {
    "Ghosts": {"Dashboard": "/dashboard", "Browse": "/ghosts"},
    "Research": {
        "Guidebook": "/guidebook",
        "Cheat Sheet*": "/cheatsheet",
    },
    "Settings": {
        "Your Profile": "/profile",
        "Configuration*": "/configuration",
        "Integrations*": "/integrations",
        "Manage Users": "/manage",
    },
    "Meta": {
        "System Logs*": "/logs",
        "Logout": "/logout",
    },
}

templates.env.globals["avatar_menu"] = {
    "Dashboard": "/dashboard",
    "Your Profile": "/profile",
    "Logout": "/logout",
}
