#pragma once

#include "trigger_engine.h"
#include "source.h"

#include <QDockWidget>
#include <memory>
#include <vector>

class QComboBox;
class QDoubleSpinBox;
class QPushButton;
class QLabel;

/**
 * Trigger configuration panel as a toggleable QDockWidget.
 *
 * Wire up:
 *   connect(triggerPanel_, &TriggerToolBar::armRequested, this, ...);
 *   connect(triggerPanel_, &TriggerToolBar::disarmRequested, this, ...);
 *
 * Show/hide by connecting the "Trigger" toolbar button to toggleViewAction().
 */
class TriggerToolBar : public QDockWidget {
    Q_OBJECT
public:
    explicit TriggerToolBar(QWidget* parent = nullptr);

    void refreshSources(const std::vector<std::shared_ptr<Source>>& sources);

    TriggerEngine::Edge edge()      const;
    TriggerEngine::Mode mode()      const;
    double              threshold() const;
    double              preSec()    const;
    double              postSec()   const;
    /** Returns {src_idx, sig_idx} or {-1,-1} if nothing selected. */
    std::pair<int,int>  selectedSignal() const;

    /** Update the status label (Armed / Idle / Fired). */
    void setStatus(const QString& text);

signals:
    void armRequested();
    void disarmRequested();

private:
    QComboBox*       signalCombo_ = nullptr;
    QComboBox*       edgeCombo_   = nullptr;
    QComboBox*       modeCombo_   = nullptr;
    QDoubleSpinBox*  threshSpin_  = nullptr;
    QDoubleSpinBox*  preSpin_     = nullptr;
    QDoubleSpinBox*  postSpin_    = nullptr;
    QPushButton*     armBtn_      = nullptr;
    QPushButton*     disarmBtn_   = nullptr;
    QLabel*          statusLabel_ = nullptr;

    // Parallel to signalCombo_ entries
    std::vector<std::pair<int,int>> sigIds_;
};
