#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <eismultiplexer.h>
#include <QMainWindow>
#include <memory>
#include <QCodeEditor>
#include <QPythonCompleter>
#include <QPythonHighlighter>
#include <QProgressBar>
#include "channelwidget.h"
#include "triggerwidget.h"
#include "pythonrunner.h"

namespace Ui
{
class MainWindow;
}

class MainWindow : public QMainWindow
{
    Q_OBJECT
    std::vector<std::shared_ptr<TriggerWidget>> triggers;
    std::vector<std::shared_ptr<ChannelWidget>> channels;
    std::vector<std::pair<uint16_t, std::shared_ptr<struct eismultiplexer>>> multiplexers;
    Ui::MainWindow *ui;
    QCodeEditor codeEditor;
    QPythonHighlighter highligter;
    QPythonCompleter completer;
    QTextEdit pythonOutput;
    PythonRunner pythonRunner;

signals:
        void channelStateChanged(uint16_t device, uint16_t channel);

public:
        explicit MainWindow(QWidget *parent = nullptr);
        ~MainWindow();

private slots:
        void onActionOpenTriggered();
        void onActionSaveTriggered();
        void onActionSaveAsTriggered();
        void runScript();
        void stopScript();
        void readState();
        void onVenvPreparationProgress(const QString& message);
        void onVenvPreparationFinished();

private:
        void enumerateDevices();
        void generateExample();
        void updateStatus();
        void disconnectDevices();
        void blockUIForVenvPreparation();
        void unblockUI();
        QString currentFilePath;
        bool isFileModified;
        bool uiBlocked;
};

#endif // MAINWINDOW_H

