#ifndef PLUGINITEM_H
#define PLUGINITEM_H

#include <QQuickItem>
#include <QImage>
#include "singleton.h"
#include "qwidgetpluginmanager.h"

class QmlWidget;
class PluginItem : public QQuickItem
{
    Q_OBJECT
    Q_PROPERTY(bool widgetVisible READ widgetVisible WRITE setWidgetVisible NOTIFY widgetVisibleChanged)
    Q_PROPERTY(QQuickItem* mapItem READ mapItem WRITE setMapItem NOTIFY mapItemChanged)
    Q_PROPERTY(int mIndex READ index WRITE setIndex NOTIFY indexChanged)
    Q_PROPERTY(QString pluginName READ pluginName WRITE setPluginName NOTIFY pluginNameChanged)
    Q_PROPERTY(QQuickWindow* rootWindow READ rootWindow WRITE setRootWindow NOTIFY rootWindowChanged)

public:
    PluginItem(QQuickItem *parent = nullptr);
    ~PluginItem();

    bool widgetVisible() const;
    QQuickItem* mapItem() const;
    QQuickWindow* rootWindow() const;
    int index() const;
    QString pluginName() const;

    void setWidgetVisible(bool widgetVisible);
    void setMapItem(QQuickItem *item);
    void setIndex(int index);
    void setPluginName(const QString &pluginName);
    void setRootWindow(QQuickWindow* rootWindow);

protected:
    virtual void updatePolish() override;
    virtual QSGNode *updatePaintNode(QSGNode *, UpdatePaintNodeData *) override;

Q_SIGNALS:
    void widgetVisibleChanged();
    void mapItemChanged();
    void indexChanged();
    void pluginNameChanged();
    void rootWindowChanged();

private:
    bool m_widgetVisible;
    QImage m_widgetImage;
    QQuickItem *m_mapItem = nullptr;
    QQuickWindow *m_rootWindow = nullptr;
    int m_index;
    QString m_pluginName;
    QWidgetPluginManager &pluginMgr = common::Singleton<QWidgetPluginManager>::GetInstance();
};

#endif // PLUGINITEM_H
