from imgui_bundle import hello_imgui, imgui
#from ..app_state import AppState
from typing import List

from .database import *

from .editor import editor

def database_docking_splits() -> List[hello_imgui.DockingSplit]:
    """
    Defines the docking layout for the database editor.
    
    Returns a list of docking splits that define the structure of the editor layout.
    
    :return: A list of `hello_imgui.DockingSplit` objects defining docking positions and sizes.
    """
    split_main_command = hello_imgui.DockingSplit()
    split_main_command.initial_dock = "MainDockSpace"
    split_main_command.new_dock = "CommandSpace"
    split_main_command.direction = imgui.Dir.down
    split_main_command.ratio = 0.3

    split_main_command2 = hello_imgui.DockingSplit()
    split_main_command2.initial_dock = "CommandSpace"
    split_main_command2.new_dock = "CommandSpace2"
    split_main_command2.direction = imgui.Dir.right
    split_main_command2.ratio = 0.3

    split_main_misc = hello_imgui.DockingSplit()
    split_main_misc.initial_dock = "MainDockSpace"
    split_main_misc.new_dock = "MiscSpace"
    split_main_misc.direction = imgui.Dir.left
    split_main_misc.ratio = 0.2

    return [split_main_misc, split_main_command, split_main_command2]

def set_database_editor_layout() -> List[hello_imgui.DockableWindow]:
    """
    Defines the dockable windows for the database editor.
    
    Creates and returns a list of dockable windows, including the database file selector, log window,
    table viewer, and editor.
    
    :param app_state: The application state.
    :return: A list of `hello_imgui.DockableWindow` objects representing the UI windows.
    """
    file_dialog = hello_imgui.DockableWindow()
    file_dialog.label = "Database"
    file_dialog.dock_space_name = "MiscSpace"
    file_dialog.gui_function = lambda: select_file()

    log = hello_imgui.DockableWindow()
    log.label = "Logs"
    log.dock_space_name = "CommandSpace2"
    log.gui_function = hello_imgui.log_gui

    table_view = hello_imgui.DockableWindow()
    table_view.label = "Table"
    table_view.dock_space_name = "MainDockSpace"
    table_view.gui_function = lambda: table()

    eeditor = hello_imgui.DockableWindow()
    eeditor.label = "Editor"
    eeditor.dock_space_name = "CommandSpace"
    eeditor.gui_function = lambda: editor()
    
    return [file_dialog, log, table_view, eeditor]

def database_editor_layout() -> hello_imgui.DockingParams:
    """
    Configures and returns the docking layout for the database editor.
    
    :param app_state: The application state.
    :return: A `hello_imgui.DockingParams` object defining the layout configuration.
    """
    docking_params = hello_imgui.DockingParams()
    docking_params.layout_name = "Database Editor"
    docking_params.docking_splits = database_docking_splits() 
    docking_params.dockable_windows = set_database_editor_layout()
    return docking_params

