# 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.

import carb.settings
import omni.kit.test
from omni.ui.tests.test_base import OmniUiTest
from pathlib import Path
import omni.kit.app
import omni.kit.window.preferences as preferences
from omni.kit.viewport.window import ViewportWindow
import omni.ui as ui

CURRENT_PATH = Path(__file__).parent
TEST_DATA_PATH = CURRENT_PATH.parent.parent.parent.parent.parent.joinpath("data").joinpath("tests")
TEST_WIDTH, TEST_HEIGHT = 1280, 600


class TestExecutionDebugWindow(OmniUiTest):
    """Test the EF Debugging Page"""

    async def setUp(self):
        """Test set-up before running each test"""
        await super().setUp()

        self._golden_img_dir = TEST_DATA_PATH.absolute().joinpath("golden_img").absolute()

        await self.create_test_area(width=TEST_WIDTH, height=TEST_HEIGHT)
        self._vw = ViewportWindow("TestWindow", width=TEST_WIDTH, height=TEST_HEIGHT)

    async def tearDown(self):
        """Test tear-down after running each test"""
        await super().tearDown()

    async def test_execution_page(self):
        """Test the EF Debugging Page"""
        title = "Execution"
        for page in preferences.get_page_list():
            if page.get_title() == title:
                # Setting keys for the test. Flag some stuff to be true to make sure toggles work.
                carb.settings.get_settings().set(page.serial_eg, False)
                carb.settings.get_settings().set(page.parallel_eg, True)
                preferences.select_page(page)

        preferences.show_preferences_window()
        await omni.kit.app.get_app().next_update_async()

        pref_window = ui.Workspace.get_window("Preferences")

        await self.docked_test_window(
            window=pref_window,
            width=TEST_WIDTH,
            height=TEST_HEIGHT,
        )

        await omni.kit.app.get_app().next_update_async()

        await self.finalize_test(golden_img_dir=self._golden_img_dir, golden_img_name=f"{title}.png")
