"""Alliance Auth hooks for PI FYAD plugin."""

from allianceauth import hooks
from allianceauth.services.hooks import MenuItemHook, UrlHook

from . import urls


class PiFyadMenuItem(MenuItemHook):
    """Menu item hook for PI FYAD."""

    def __init__(self):
        super().__init__(
            text="PI Manager",
            classes="fas fa-industry",
            url_name="pi_fyad:dashboard",
            navactive=["pi_fyad:"],
        )

    def render(self, request):
        if request.user.has_perm("pi_fyad.view_pi"):
            return MenuItemHook.render(self, request)
        return ""


@hooks.register("menu_item_hook")
def register_menu():
    return PiFyadMenuItem()


@hooks.register("url_hook")
def register_urls():
    return UrlHook(urls, "pi_fyad", r"^pi/")
