from django.urls import reverse

class NavItem:
    def __init__(self, name: str, icon: str, path: str):
        self.__name = name
        self.__icon = icon
        self.__path = path

    @property
    def name(self):
        return self.__name
    
    @property
    def icon(self):
        return self.__icon
    
    @property
    def path(self):
        return self.__path if (self.__path.startswith("/") or "://" in self.__path) else reverse(self.__path)

class NavSection:
    def __init__(self, name: str, icon: str):
        self.__items = []
        self.__name = name
        self.__icon = icon

    @property
    def name(self):
        return self.__name

    @property
    def icon(self):
        return self.__icon

    def add_item(self, item: NavItem):
        if not item in self.__items:
            self.__items.append(item)

    def del_item(self, item: NavItem):
        while item in self.__items:
            self.__items.remove(item)

    def del_item_by_name(self, name: str):
        for item in self.__items:
            if item.name == name:
                del(item)

    @property
    def items(self):
        return self.__items

class Navigation:
    def __init__(self):
        self.__sections = []

    def add_section(self, section: NavSection):
        if not section in self.__sections:
            self.__sections.append(section)

    def del_section(self, section: NavSection):
        while section in self.__sections:
            self.__sections.remove(section)

    def del_section_by_name(self, name: str):
        for section in self.__sections:
            if section.name == name:
                del(section)

    @property
    def sections(self):
        return self.__sections