# Copyright (c) 2018-2020, 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__ = ["InspectorWindow"]

import omni.ui as ui
import carb.events
import omni.kit.app
from typing import cast

from .tree.inspector_tree import WindowListModel, WindowItem
from .demo_window import InspectorDemoWindow
from .inspector_widget import InspectorWidget

from pathlib import Path

ICON_PATH = Path(__file__).parent.parent.parent.parent.parent.joinpath("icons")


class InspectorWindow:
    """The inspector window"""

    def __init__(self):
        window_flags = ui.WINDOW_FLAGS_NO_SCROLLBAR
        self._window = ui.Window(
            "Inspector",
            width=1000,
            height=800,
            flags=window_flags,
            dockPreference=ui.DockPreference.RIGHT_TOP,
            padding_x=0,
            padding_y=0,
        )

        # Create a Demo Window to show case the general feature
        self._demo_window = None
        use_demo_window = carb.settings.get_settings().get("/exts/omni.kit.window.inspector/use_demo_window")
        with self._window.frame:
            if use_demo_window:
                self._demo_window = InspectorDemoWindow()
                self._inspector_widget = InspectorWidget(self._demo_window.window)
            else:
                self._inspector_widget = InspectorWidget(None)

    def destroy(self):
        """
        Called by extension before destroying this object. It doesn't happen automatically.
        Without this hot reloading doesn't work.
        """
        if self._demo_window:
            self._demo_window.destroy()
            self._demo_window = None

        self._inspector_widget.destroy()
        self._inspector_widget = None
        self._window = None
