#pragma once

#include <QWidget>
#include <QTabWidget>
#include <QVBoxLayout>
#include <QHash>
#include <QString>

class EditorTab;
class Settings;
class SearchPanel;
class FileSearchPanel;

// ---------------------------------------------------------------------------
// EditorPanel – Rechtes Panel: Tab-Leiste + Editoren + Such/Ersetzen-Panel.
// ---------------------------------------------------------------------------
class EditorPanel : public QWidget
{
    Q_OBJECT

public:
    explicit EditorPanel(Settings *settings, QWidget *parent = nullptr);

public slots:
    void openFile(const QString &filePath);
    void saveCurrentFile();
    void saveCurrentFileAs();
    void saveAllFiles();
    void setSearchRoot(const QString &path);
    void showSearchPanel();
    void showFileSearchPanel();
    void goToLine(const QString &filePath, int line);

    // Session
    QStringList openFilePaths() const;
    QString     activeFilePath() const;
    void        restoreSession(const QStringList &files, const QString &activeFile);
    void undo();
    void redo();

signals:
    void currentFileSaved(const QString &filePath);

private slots:
    void onTabCloseRequested(int index);
    void onCurrentTabChanged(int index);

private:
    void       setupUi();
    int        findTabForFile(const QString &filePath) const;
    EditorTab *currentTab() const;

    Settings       *m_settings        = nullptr;
    QVBoxLayout    *m_layout          = nullptr;
    QTabWidget     *m_tabWidget       = nullptr;
    SearchPanel    *m_searchPanel     = nullptr;
    FileSearchPanel *m_fileSearch     = nullptr;

    QHash<QString, EditorTab *> m_openTabs;
};
