
__all__ = ["WidgetCollectionFrame"]

# from typing import Union, Any

from .create_widget import PropertyType
import omni.ui as ui

from .create_widget import create_property_widget
from .widget_builder import PropertyWidgetBuilder


class WidgetCollectionFrame:

    parents = {}  # For later deletion of parents

    def __init__(self, frame_label: str, widget: ui.Widget) -> None:

        self._models = []
        self._widget = widget
        self._frame_widget = ui.CollapsableFrame(frame_label, height=0, build_fn=self.build_ui)

    def destroy(self):
        """"""
        self._frame_widget.clear()
        self._frame_widget = None

    def build_ui(self):
        with ui.VStack(height=0, spacing=5, style={"VStack": {"margin_width": 10}}):
            ui.Spacer(height=5)
            self._build_ui()
            ui.Spacer(height=5)

    def _rebuild(self):
        if self._frame_widget:
            self._frame_widget.rebuild()

    def _add_property(
        self,
        widget: ui.Widget,
        property: str,
        property_type: PropertyType,
        range_from=0,
        range_to=0,
        speed=1,
        has_reset=True,
        tooltip="",
        label_width=150,
    ):
        with ui.HStack(skip_draw_when_clipped=True):
            PropertyWidgetBuilder._create_label(property, label_width=label_width)
            property_widget, model = create_property_widget(
                widget, property, property_type, range_from, range_to, speed
            )
            self._models.append(model)
            # if has_reset:
            # button = PropertyWidgetBuilder._build_reset_button(path)
            # model.set_reset_button(button)

        return property_widget, model

    # def _add_setting_combo(
    #     self, name: str, path: str, items: Union[list, dict], callback=None, has_reset=True, tooltip=""
    # ):
    #     with ui.HStack(skip_draw_when_clipped=True):
    #         PropertyWidgetBuilder._create_label(name, path, tooltip)
    #         property_widget, model = create_property_widget_combo(widget, items)

    #         #if has_reset:
    #         #    button = PropertyWidgetBuilder._build_reset_button(path)
    #         #    model.set_reset_button(button)
    #     return property_widget

    def _build_ui(self):
        """ virtual function that will be called in the Collapsable frame """
        pass
