from nicegui import ui
from custom_components.log import MyLog
from datas.global_data import global_data
from main_events import handle_click, handle_cpu_transform

# 统一设置按钮为方形
ui.button.default_props('square')

@ui.refreshable
def user_path():
    path_input = ui.input().props('square outlined dense disable').classes("flex-grow min-w-0")
    path_input.bind_value_from(global_data, 'user_select_path')

def root():
    with ui.column().classes('w-full h-full flex flex-col'):
        with ui.card().classes('w-full flex'):
            with ui.row().classes('justify-center items-center w-full'):
                ui.button("请选择文件", on_click = handle_click)
                ui.label("当前选择文件路径：")
                user_path()

        # 上半部分
        with ui.column().classes('w-full flex-grow overflow-auto min-h-[350px]'):
            with ui.tabs().props("dense align='left'").classes('w-full').classes("bg-teal text-yellow shadow-2") as tabs:
                tab_home = ui.tab('大纲转说明')
                tab_profile = ui.tab('其他小工具')
                tab_settings = ui.tab('设置')

            with ui.tab_panels(tabs, value = tab_home).classes('w-full flex-grow'):
                with ui.tab_panel(tab_home):
                    ui.button(
                        "CPU-大纲转说明(测试项描述分点)", icon = "swap_horiz", on_click = lambda e: handle_cpu_transform(log = log_element)
                    )

                with ui.tab_panel(tab_profile):
                    ui.label('欢迎来到其他小工具')

                with ui.tab_panel(tab_settings):
                    ui.label("欢迎来到设置界面")

        ui.linear_progress(color = 'info', show_value = False, size = '30px').bind_value_from(global_data,
                                                                                              'progress_value').props('stripe')
        log_element = MyLog().classes('flex-grow overflow-auto min-h-[270px] select-text').style("white-space:pre-wrap;")
        log_element.debug_emit("界面初始化完成...")

ui.run(root, language = 'zh-CN', native = True, window_size = (1200, 900), reload = False)
