import carb
import omni.ext
from typing import List, Sequence
from pxr import Kind, Sdf, Usd, UsdGeom, Vt, UsdRender
from omni.kit.property.usd.usd_property_widget import MultiSchemaPropertiesWidget, UsdPropertyUiEntry

class ProductSchemaAttributesWidget(MultiSchemaPropertiesWidget):

    def __init__(self, title: str, schema, schema_subclasses: list, include_list: list = [], exclude_list: list = [], api_schemas: Sequence[str] = None, group_api_schemas: bool = False):
        super().__init__(title, schema, schema_subclasses, include_list, exclude_list, api_schemas, group_api_schemas)

    def on_new_payload(self, payload):
        """
        See PropertyWidget.on_new_payload
        """
        if not super().on_new_payload(payload):
            return False

        if not self._payload or len(self._payload) == 0:
            return False

        used = []
        for prim_path in self._payload:
            prim = self._get_prim(prim_path)
            if not prim or not prim.IsA(self._schema):
                return False
            used += [attr for attr in prim.GetAttributes() if attr.GetName() in self._schema_attr_names and not attr.IsHidden()]

        return used

    def _customize_props_layout(self, attrs):
        from omni.kit.property.usd.custom_layout_helper import (
            CustomLayoutFrame,
            CustomLayoutGroup,
            CustomLayoutProperty,
        )
        from omni.kit.window.property.templates import (
            SimplePropertyWidget,
            LABEL_WIDTH,
            LABEL_HEIGHT,
            HORIZONTAL_SPACING,
        )

        frame = CustomLayoutFrame(hide_extra=False)
        anchor_prim = self._get_prim(self._payload[-1])

        with frame:
            with CustomLayoutGroup("Render Product"):
                CustomLayoutProperty("resolution", "Resolution")
                CustomLayoutProperty("camera", "Camera")
                CustomLayoutProperty("orderedVars", "Ordered Vars")

                # https://github.com/PixarAnimationStudios/USD/commit/dbbe38b94e6bf113acbb9db4c85622fe12a344a5
                if hasattr(UsdRender.Tokens, 'disableMotionBlur'):
                    CustomLayoutProperty("disableMotionBlur", "Disable Motion Blur")

        return frame.apply(attrs)
