# 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__ = ["InspectorDemoWindow"]

from typing import cast
from pathlib import Path
import omni.ui as ui

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


class InspectorDemoWindow:
    """The demo window for the inspector"""

    @property
    def window(self) -> ui.Window:
        return cast(ui.Window, self._window)

    def destroy(self):
        self._window = None

    def __init__(self):
        self._window = ui.Window("DemoWindow", width=300, height=900)

        style_testing = {
            "Label:hovered": {"color": 0xFF00FFFF},
            "Label::title": {"font_size": 18, "color": 0xFF00EEEE, "alignment": ui.Alignment.LEFT},
            "Label": {"font_size": 14, "color": 0xFFEEEEEE},
            "Button.Label": {"font_size": 15, "color": 0xFF33FF33},
            "Line": {"color": 0xFFFF0000},
            "Slider": {"draw_mode": ui.SliderDrawMode.FILLED, "secondary_color": 0xFFAA0000},
            "Stack::blue": {"stack_direction": ui.Direction.RIGHT_TO_LEFT},
            "Button::green": {
                "background_color": 0xFF333333,
                "color": 0xFF00FFFF,
                "border_width": 2,
                "border_color": 0xFF00FF00,
                "border_radius": 3,
                "corner_flag": ui.CornerFlag.BOTTOM,
                "alignment": ui.Alignment.CENTER,
            },
            "Button.Image::green": {
                # "image_url": "c:/path/to/an/image.png",
                "fill_policy": ui.FillPolicy.PRESERVE_ASPECT_FIT
            },
        }

        self._window.frame.set_style(style_testing)

        with self._window.frame:
            with ui.VStack():
                ui.Label("Title", height=0, name="title")
                with ui.HStack(height=0):
                    ui.Label("THis is Cool", style={"Label": {"font_size": 12, "color": 0xFF0000FF}})

                    def button_fn(name: str):
                        print(f"Executed Button Labled {name}")

                    ui.Button("Button 1", name="button1", clicked_fn=lambda n="Button 1": button_fn(n))
                    ui.Button("Button 2", name="green", clicked_fn=lambda n="Button 2": button_fn(n))

                ui.Line(height=2)
                ui.Spacer(height=10)
                ui.IntSlider(height=0, min=0, max=100)
                ui.Spacer(height=10)
                with ui.HStack(height=0):
                    ui.Label("Field", style={"color": 0xFF00FF00})
                    ui.StringField().model.set_value("This is Cool ")

                with ui.HStack(height=0):
                    ui.Rectangle(
                        height=30,
                        style={
                            "backgroun_color": 0xFFAAAAAA,
                            "border_width": 2,
                            "border_radius": 3,
                            "border_color": 0xFFAADDAA,
                        },
                    )

                with ui.Frame(height=100):
                    with ui.Placer(draggable=True):
                        ui.Rectangle(width=20, height=20, style={"background_color": 0xFF0000FF})

                ui.ComboBox(1, "One", "Two", "Inspector", "Is", "Amazing", height=0)
                ui.Spacer(height=10)

                with ui.VGrid(height=50, column_count=5, row_height=50):
                    for i in range(5):
                        ui.Rectangle(style={"background_color": 0xFF000000})
                        ui.Rectangle(style={"background_color": 0xFFFFFFFF})

                with ui.HGrid(height=50, column_width=30, row_count=3):
                    for i in range(10):
                        ui.Rectangle(style={"background_color": 0xFF00FFAA})
                        ui.Rectangle(style={"background_color": 0xFFF00FFF})

                ui.Spacer(height=10)
                with ui.CollapsableFrame(title="Image", height=0):
                    # ui.Image("/dfagnou/Desktop/omniverse_background.png", height=100)
                    ui.Image(f"{ICON_PATH}/sync.svg", height=100)

                with ui.HStack(height=30):
                    ui.Triangle(height=20, style={"background_color": 0xFFAAFFAA})
                    ui.Circle(style={"background_color": 0xFFAAFFFF})

                canvas = ui.CanvasFrame(height=20, style={"background_color": 0xFFDD00DD})
                # canvas.set_pan_key_shortcut(1, carb.K)
                with canvas:
                    # ui.Image("/dfagnou/Desktop/omniverse_background.png")
                    ui.Image(f"{ICON_PATH}/sync.svg", height=20)
