#pragma once

#include <QDialog>
#include <QTreeWidget>
#include <QTreeWidgetItem>
#include <QLabel>
#include <QPushButton>
#include <QProgressBar>
#include <QLineEdit>
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QFutureWatcher>
#include <QString>

#include "DeadCodeAnalyzer.h"

class DeadCodeDialog : public QDialog
{
    Q_OBJECT

public:
    explicit DeadCodeDialog(QWidget *parent = nullptr);

    void setProjectRoot(const QString &path);

signals:
    void fileLineRequested(const QString &filePath, int line);

private slots:
    void onAnalyze();
    void onAnalysisFinished();
    void onProgressUpdate(int filesScanned, int filesTotal,
                          const QString &currentFile);
    void onItemActivated(QTreeWidgetItem *item, int column);
    void onExportClicked();

protected:
    void closeEvent(QCloseEvent *event) override;

private:
    void setupUi();

    QString        m_projectRoot;

    // Einstellungen
    QLineEdit     *m_excludeEdit   = nullptr;

    // Steuerung
    QPushButton   *m_btnAnalyze    = nullptr;
    QPushButton   *m_btnExport     = nullptr;

    // Fortschritt
    QProgressBar  *m_progress      = nullptr;
    QLabel        *m_progressLabel = nullptr;

    // Status + Ergebnisse
    QLabel        *m_statusLabel   = nullptr;
    QTreeWidget   *m_results       = nullptr;

    DeadCodeAnalyzer *m_analyzer   = nullptr;
    QFutureWatcher<QList<DeadCodeAnalyzer::DeadFunction>> *m_watcher = nullptr;
};
