#pragma once

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

#include <QDialog>
#include <memory>
#include <vector>

class QComboBox;
class QDoubleSpinBox;
class QPushButton;

/**
 * Trigger configuration dialog.
 * Non-modal: stays visible while the user watches the plot.
 */
class TriggerDialog : public QDialog {
    Q_OBJECT
public:
    explicit TriggerDialog(
        const std::vector<std::shared_ptr<Source>>& sources,
        QWidget* parent = nullptr);

    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 none selected
    std::pair<int,int> selectedSignal() const;

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

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

    QComboBox*       signalCombo_ = nullptr;
    QComboBox*       edgeCombo_   = nullptr;
    QComboBox*       modeCombo_   = nullptr;
    QDoubleSpinBox*  threshSpin_  = nullptr;
    QDoubleSpinBox*  preSpin_     = nullptr;
    QDoubleSpinBox*  postSpin_    = nullptr;
    QPushButton*     armBtn_      = nullptr;

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