import asyncio
import carb
import omni.usd
import omni.ui as ui
from omni.kit import ui_test
from omni.kit.menu.utils import MenuItemDescription, MenuLayout


async def file_test_func_file_add_reference(tester, menu_item: MenuItemDescription):
    from carb.input import KeyboardInput

    menu_widget = ui_test.get_menubar()
    await menu_widget.find_menu("File").click()
    await menu_widget.find_menu("Add Reference").click()
    await ui_test.human_delay()

    dir_widget = ui_test.find("Select File//Frame/**/StringField[*].identifier=='filepicker_directory_path'")
    await ui_test.human_delay()

    await dir_widget.input(carb.tokens.acquire_tokens_interface().resolve("${kit}/exts/omni.kit.menu.file/data/tests"))
    await ui_test.human_delay()

    await tester.find_content_file("Select File", "sphere.usda").click(double=True)
    await ui_test.human_delay(20)

    # verify reference was added...
    stage =  omni.usd.get_context().get_stage()
    prim_list = [prim.GetPath().pathString for prim in stage.TraverseAll()]
    tester.assertTrue(len(prim_list) > 0)


async def file_test_func_file_add_payload(tester, menu_item: MenuItemDescription):
    from carb.input import KeyboardInput

    menu_widget = ui_test.get_menubar()
    await menu_widget.find_menu("File").click()
    await menu_widget.find_menu("Add Payload").click()
    await ui_test.human_delay()

    dir_widget = ui_test.find("Select File//Frame/**/StringField[*].identifier=='filepicker_directory_path'")
    await ui_test.human_delay()

    await dir_widget.input(carb.tokens.acquire_tokens_interface().resolve("${kit}/exts/omni.kit.menu.file/data/tests"))
    await ui_test.human_delay()

    await tester.find_content_file("Select File", "sphere.usda").click(double=True)
    await ui_test.human_delay(20)

    # verify payload was added...
    stage =  omni.usd.get_context().get_stage()
    prim_list = [prim.GetPath().pathString for prim in stage.TraverseAll()]
    tester.assertTrue(len(prim_list) > 0)
