from .utils import QUICK_JOIN_ENABLED
from .utils import SESSION_LIST_SELECT, SESSION_LIST_SELECT_DEFAULT_SESSION, SESSION_LIST_SELECT_LAST_SESSION
import carb.settings
import omni.ui as ui
from omni.kit.widget.settings import SettingType
from omni.kit.window.preferences import PreferenceBuilder




class LiveSessionPreferences(PreferenceBuilder):
    SETTING_PAGE_NAME = "Live"

    def __init__(self):
        super().__init__(LiveSessionPreferences.SETTING_PAGE_NAME)
        self._settings = carb.settings.get_settings()
        self._checkbox_quick_join_enabled = None
        self._combobox_session_list_select = None

    def destroy(self):
        self._settings = None
        self._checkbox_quick_join_enabled = None
        self._combobox_session_list_select = None

    def build(self):
        self._checkbox_quick_join_enabled = None
        self._combobox_session_list_select = None
        with ui.VStack(height=0):
            with self.add_frame("Join"):
                with ui.VStack():
                    checkbox = self.create_setting_widget(
                        "Quick Join Enabled",
                        QUICK_JOIN_ENABLED,
                        SettingType.BOOL,
                        tooltip="Quick Join, creates and joins a Default session and bypasses dialogs."
                    )
                    self._checkbox_quick_join_enabled = checkbox
                    ui.Spacer()
                    combo = self.create_setting_widget_combo(
                        "Session List Select",
                        SESSION_LIST_SELECT,
                        [SESSION_LIST_SELECT_DEFAULT_SESSION, SESSION_LIST_SELECT_LAST_SESSION]
                    )
                    self._combobox_session_list_select = combo
                    ui.Spacer()
            ui.Spacer(height=10)
