# Copyright (c) 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.
#

import carb
import omni.usd
from pathlib import Path
from .geom_scheme_delegate import GeomPrimSchemeDelegate
from .path_scheme_delegate import PathPrimSchemeDelegate
from .material_scheme_delegate import MaterialPrimSchemeDelegate, ShaderPrimSchemeDelegate

TEST_DATA_PATH = ""


class BundlePropertyWidgets(omni.ext.IExt):
    def __init__(self):
        self._registered = False
        super().__init__()

    def on_startup(self, ext_id):
        self._register_widget()

        manager = omni.kit.app.get_app().get_extension_manager()
        extension_path = manager.get_extension_path(ext_id)
        global TEST_DATA_PATH
        TEST_DATA_PATH = Path(extension_path).joinpath("data").joinpath("tests")

    def on_shutdown(self):
        self._unregister_widget()

    def _register_widget(self):
        import omni.kit.window.property as p

        w = p.get_window()
        w.register_scheme_delegate("prim", "xformable_prim", GeomPrimSchemeDelegate())
        w.register_scheme_delegate("prim", "path_prim", PathPrimSchemeDelegate())
        w.register_scheme_delegate("prim", "material_prim", MaterialPrimSchemeDelegate())
        w.register_scheme_delegate("prim", "shade_prim", ShaderPrimSchemeDelegate())
        physics_widgets = [
            "physics_components",
            "physics_prim",
            "joint_prim",
            "vehicle_prim",
            "physics_material",
            "custom_properties",
        ]
        anim_graph_widgets = ["anim_graph", "anim_graph_node"]
        w.set_scheme_delegate_layout(
            "prim",
            [
                "path_prim",
                "basis_curves_prim",
                "point_instancer_prim",
                "material_prim",
                "xformable_prim",
                "shade_prim",
                "audio_settings",
            ]
            + physics_widgets
            + anim_graph_widgets,
        )

    def _unregister_widget(self):
        import omni.kit.window.property as p

        w = p.get_window()
        w.reset_scheme_delegate_layout("prim")
        w.unregister_scheme_delegate("prim", "xformable_prim")
        w.unregister_scheme_delegate("prim", "path_prim")
        w.unregister_scheme_delegate("prim", "material_prim")
        w.unregister_scheme_delegate("prim", "shade_prim")
