from typing import List

import carb.settings
import carb.tokens
import omni.client
import omni.ext
import omni.ui as ui
from omni.kit.welcome.window import register_page
from omni.ui import constant as fl

from .style import ABOUT_PAGE_STYLE

_extension_instance = None


class AboutPageExtension(omni.ext.IExt):
    def on_startup(self, ext_id):
        self.__ext_name = omni.ext.get_extension_name(ext_id)
        register_page(self.__ext_name, self.build_ui)

    def on_shutdown(self):
        global _extension_instance
        _extension_instance = None

        self._about_widget = None

    def build_ui(self) -> None:
        with ui.ZStack(style=ABOUT_PAGE_STYLE):
            # Background
            ui.Rectangle(style_type_name_override="Content")
            with ui.VStack():
                with ui.VStack(height=fl._find("welcome_page_title_height")):
                    ui.Spacer()
                    ui.Label("ABOUT", height=0, alignment=ui.Alignment.CENTER, style_type_name_override="Title.Label")
                    ui.Spacer()

                with ui.HStack():
                    ui.Spacer(width=fl._find("welcome_content_padding_x"))
                    with ui.VStack():
                        with ui.ZStack():
                            ui.Rectangle(style_type_name_override="Info")
                            self.__build_content()
                    ui.Spacer(width=fl._find("welcome_content_padding_x"))

                ui.Spacer(height=fl._find("welcome_content_padding_y"))

    def __build_content(self):
        import omni.kit.app
        manager = omni.kit.app.get_app().get_extension_manager()
        manager.set_extension_enabled_immediate("omni.kit.window.about", True)

        from omni.kit.window.about import AboutWidget
        with ui.Frame():
            self._about_widget = AboutWidget()
