# Copyright (c) 2023, 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__ = ["WelcomeWindow"]

from .widget import WelcomeWidget
from typing import Optional
import omni.ui as ui


class WelcomeWindow(ui.Window):
    """The class that represents the window"""

    def __init__(self, title: str, buttons: dict, *args, **kwargs):
        super().__init__(title, *args, **kwargs)
        self.__buttons = buttons
        self.__widget: Optional[WelcomeWidget] = None

        # Set the function that is called to build widgets when the window is visible
        self.frame.set_build_fn(self.__build_fn)

    def __destroy_widget(self):
        if self.__widget:
            self.__widget.destroy()
            self.__widget = None

    def __build_fn(self):
        # Destroy any existing WelcomeWidget
        self.__destroy_widget()
        # Add the Welcomwidget
        self.__widget = WelcomeWidget(self.__buttons)

    def destroy(self):
        # It will destroy all the children
        self.__destroy_widget()
        super().destroy()

    @property
    def wlcome_widget(self):
        return self.__widget
