/**
 * @file MainWindow.h
 * @brief Top-level window: toolbar, source dock, plot grid, trigger/history
 *        bars, stats dialog. Owns the Hub, the shared GlobalView, and the
 *        60 Hz repaint/refresh timer.
 */

#pragma once

#include "Hub.h"
#include "PlotWidget.h"   /* GlobalView */

#include <QMainWindow>

class QToolButton;
class QComboBox;
class QLineEdit;
class QLabel;
class QTimer;
class QDockWidget;

namespace shq {

class PlotGrid;
class SourceSidebar;
class TriggerBar;
class HistoryBar;
class StatsDialog;

class MainWindow : public QMainWindow {
    Q_OBJECT
public:
    explicit MainWindow(const QString& host, uint16_t port,
                        QWidget* parent = nullptr);

private Q_SLOTS:
    void onConnectedChanged(bool connected);
    void onSourcesChanged();
    void onConfigChanged(const QString& sourceId);
    void onStatsChanged();
    void onTriggerStateChanged();
    void onHistoryInfoChanged();
    void onTick();

    void togglePause();
    void toggleHistory();
    void openAddSourceDialog();
    void doConnect();

private:
    void buildToolbar();

    Hub        hub_;
    GlobalView gv_;

    PlotGrid*      grid_   = nullptr;
    SourceSidebar* sidebar_= nullptr;
    QDockWidget*   sideDock_ = nullptr;
    TriggerBar*    trigBar_= nullptr;
    HistoryBar*    histBar_= nullptr;
    StatsDialog*   stats_  = nullptr;

    QToolButton* pauseBtn_   = nullptr;
    QToolButton* cursorBtn_  = nullptr;
    QToolButton* trigBtn_    = nullptr;
    QToolButton* histBtn_    = nullptr;
    QComboBox*   winCombo_   = nullptr;
    QLineEdit*   hostEdit_   = nullptr;
    QLineEdit*   portEdit_   = nullptr;
    QLabel*      ledLbl_     = nullptr;

    QTimer* timer_ = nullptr;
};

} /* namespace shq */
