#pragma once

#include <wx/frame.h>
#include <wx/timer.h>
#include <wx/webview.h>
#include <string>
#include <utility>
#include <vector>

struct SimPoint {
    double lat;
    double lon;
};

struct ZoneInfo {
    double      lat;
    double      lon;
    std::string name;
};

class MapSimFrame : public wxFrame {
public:
    MapSimFrame(wxWindow* parent,
                double centerLat = 53.3, double centerLon = 10.39,
                const std::vector<ZoneInfo>& zoneInfos = {});

    void AddSimPoint(double lat, double lon);
    void StartSimulation();

private:
    wxWebView*  m_webView  = nullptr;
    wxTimer     m_simTimer;
    size_t      m_simIndex = 0;

    std::vector<SimPoint>   m_route;
    std::vector<ZoneInfo>   m_zoneInfos;
    bool                    m_pageLoaded = false;

    void SendPositionToEngine(double lat, double lon);

    void syncZonesOnMap();

    void OnScriptMessage(wxWebViewEvent& event);
    void OnWebViewLoaded(wxWebViewEvent& event);
    void OnGameStateChanged(wxEvent& event);
    void OnClose(wxCloseEvent& event);
    void OnPlay(wxCommandEvent& event);
    void OnClear(wxCommandEvent& event);
    void OnSimTimer(wxTimerEvent& event);

    wxDECLARE_EVENT_TABLE();
};
