from pathlib import Path

import gradio as gr

from gradio_sync3dcompare import Sync3DCompare


ROOT = Path(__file__).resolve().parent
SAMPLE_DIR = (ROOT / "demo" / "sample_data").resolve()
MESH_A = SAMPLE_DIR / "mesh_a.glb"
MESH_B = SAMPLE_DIR / "mesh_b.glb"
POINT_SIZE = 0.5
DEFAULT_ZOOM = 1
MIN_ZOOM = 0.5
MAX_ZOOM = 16.0


def load_comparison():
    return [
        {"name": "Mesh A", "path": str(MESH_A)},
        {"name": "Mesh B", "path": str(MESH_B)},
    ]


with gr.Blocks(title="Synchronized GLB Comparison") as demo:
    gr.Markdown("# Synchronized GLB Comparison")
    gr.Markdown(
        "Click the button to load two GLB files into a side-by-side viewer with synchronized orbit, zoom, and pan."
    )

    load_button = gr.Button("Load Comparison")
    viewer = Sync3DCompare(
        value=[],
        label="3D Comparison",
        render_mode="points",
        sync_camera=True,
        point_size=POINT_SIZE,
        default_zoom=DEFAULT_ZOOM,
        min_zoom=MIN_ZOOM,
        max_zoom=MAX_ZOOM,
        height=500,
        num_views=2,
    )

    load_button.click(fn=load_comparison, outputs=viewer)


if __name__ == "__main__":
    demo.launch()