#pragma once

#include <QMainWindow>
#include <QSplitter>
#include <QMenuBar>
#include <QStatusBar>
#include <QAction>
#include <memory>

#include "ProjectManager.h"
#include "Settings.h"
#include "ThemeManager.h"

class FileTreePanel;
class EditorPanel;

// ---------------------------------------------------------------------------
// MainWindow – Hauptfenster. Besitzt alle zentralen Dienste und das Layout.
// ---------------------------------------------------------------------------
class MainWindow : public QMainWindow
{
    Q_OBJECT

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

protected:
    void closeEvent(QCloseEvent *event) override;

private slots:
    // Datei
    void onNewFile();
    void onOpenFile();
    void onOpenProject();
    void onCloseProject();
    void onSave();
    void onSaveAs();
    void onSaveAll();
    // Bearbeiten
    void onUndo();
    void onRedo();
    void onShowSearch();
    void onShowFileSearch();
    // Ansicht
    void onToggleDarkMode(bool checked);
    // Hilfe
    void onAbout();
    // Intern
    void onProjectOpened(const QString &path);
    void onProjectClosed();

private:
    void setupUi();
    void setupMenuBar();
    void setupStatusBar();
    void connectSignals();
    void applyInitialTheme();
    void saveWindowState();
    void restoreWindowState();

    // Dienste
    std::unique_ptr<ProjectManager> m_projectManager;
    std::unique_ptr<Settings>       m_settings;
    std::unique_ptr<ThemeManager>   m_themeManager;

    // Layout
    QSplitter     *m_splitter = nullptr;
    FileTreePanel *m_fileTree = nullptr;
    EditorPanel   *m_editor   = nullptr;

    // Aktionen
    QAction *m_actNewFile     = nullptr;
    QAction *m_actOpenFile    = nullptr;
    QAction *m_actOpenProject = nullptr;
    QAction *m_actClose       = nullptr;
    QAction *m_actSave        = nullptr;
    QAction *m_actSaveAs      = nullptr;
    QAction *m_actSaveAll     = nullptr;
    QAction *m_actQuit        = nullptr;
    QAction *m_actUndo        = nullptr;
    QAction *m_actRedo        = nullptr;
    QAction *m_actSearch      = nullptr;
    QAction *m_actFileSearch  = nullptr;
    QAction *m_actDarkMode    = nullptr;
    QAction *m_actAbout       = nullptr;
};
