#pragma once

#include <QWidget>
#include <QTreeView>
#include <QFileSystemModel>
#include <QVBoxLayout>
#include <QLabel>
#include <QString>
#include <QMenu>
#include <QAction>

// ---------------------------------------------------------------------------
// FileTreePanel – Left panel showing the project directory tree.
// Emits fileActivated(path) when the user double-clicks a file.
// Supports creating new files/folders via context menu.
// ---------------------------------------------------------------------------
class FileTreePanel : public QWidget
{
    Q_OBJECT

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

    void setRootPath(const QString &path);
    void clearRoot();
    void triggerNewFile();   // Called from MainWindow menu action

signals:
    void fileActivated(const QString &filePath);
    void fileCreated(const QString &filePath);

private slots:
    void onItemActivated(const QModelIndex &index);
    void onContextMenuRequested(const QPoint &pos);
    void onNewFile();
    void onNewFolder();
    void onDeleteEntry();

private:
    void setupUi();

    // Returns the directory of the currently selected item
    QString selectedDirectory() const;

    QVBoxLayout      *m_layout  = nullptr;
    QLabel           *m_label   = nullptr;
    QTreeView        *m_tree    = nullptr;
    QFileSystemModel *m_model   = nullptr;
};
