#pragma once
#include <wx/wx.h>
#include <wx/webview.h>
#include "canvas/CanvasState.h"

// ── Three.js-based 3D viewer ─────────────────────────────────────────────────
// Replaces the OpenGL View3DFrame when available.
// The HTML/JS viewer is loaded from viewer3d.html (next to the exe),
// then layout JSON is injected via RunScript("loadLayout(...)").

class View3DWebFrame : public wxFrame {
public:
    View3DWebFrame(wxWindow* parent, const MC::CanvasState& state);

    // Call whenever the layout changes
    void RefreshLayout(const MC::CanvasState& state);

private:
    void OnClose(wxCloseEvent& e);
    void OnWebViewLoaded(wxWebViewEvent& e);
    void OnScriptMessage(wxWebViewEvent& e);
    void InjectLayout();

    wxWebView*             m_webView    = nullptr;
    const MC::CanvasState* m_state      = nullptr;
    bool                   m_pageReady  = false;
    wxString               m_pendingJson;

    wxDECLARE_EVENT_TABLE();
};
