#pragma once

#include <QAction>
#include <QColor>
#include <QFrame>
#include <QHash>
#include <QList>
#include <QPointer>
#include <QSet>
#include <QSize>

class PopupMenuWindow : public QFrame {
    Q_OBJECT

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

    void setActions(const QList<QAction *> &actions, const QSet<QAction *> &launcherActions = {});
    void setPreferredMaxWidth(int width);
    int actionCount() const;
    bool containsGlobal(const QPoint &globalPos) const;
    QRect actionGlobalRect(QAction *action) const;
    QColor backgroundFillColor() const;
    QSize sizeHint() const override;

signals:
    void actionHovered(QAction *action);
    void actionTriggered(QAction *action);

private:
    void clearRows();
    void refreshGeometry();

    QList<QPointer<QWidget>> rowWidgets_;
    QHash<QAction *, QPointer<QWidget>> actionRows_;
    int actionCount_ = 0;
    int preferredMaxWidth_ = 0;

protected:
    void paintEvent(QPaintEvent *event) override;
};
