# Copyright (c) 2021-2022, NVIDIA CORPORATION.  All rights reserved.
#
# NVIDIA CORPORATION and its licensors retain all intellectual property
# and proprietary rights in and to this software, related documentation
# and any modifications thereto.  Any use, reproduction, disclosure or
# distribution of this software and related documentation without an express
# license agreement from NVIDIA CORPORATION is strictly prohibited.
#
__all__ = ["ViewportRenderMenuBarExtension", "get_instance", "SingleRenderMenuItemBase", "SingleRenderMenuItem"]

from .menu_item.single_render_menu_item import SingleRenderMenuItem, SingleRenderMenuItemBase
from .renderer_menu_container import RendererMenuContainer
import omni.ext
from typing import Callable


_extension_instance = None


def get_instance():
    global _extension_instance
    return _extension_instance


class ViewportRenderMenuBarExtension(omni.ext.IExt):
    """The Entry Point for the Render Settings in Viewport Menu Bar"""

    def on_startup(self, ext_id):
        self._render_menu = RendererMenuContainer()

        global _extension_instance
        _extension_instance = self

    def register_menu_item_type(self, menu_item_type: Callable[..., "SingleRenderMenuItemBase"]):
        """
        Register a custom menu type for the default created renderer

        Args:
            menu_item_type: callable that will create the menu item
        """
        if self._render_menu:
            self._render_menu.set_menu_item_type(menu_item_type)

    def on_shutdown(self):
        if self._render_menu:
            self._render_menu.destroy()
        self._render_menu = None

        global _extension_instance
        _extension_instance = None
