#ifndef AVATAR_WIDGET_H
#define AVATAR_WIDGET_H

#include <QWidget>
#include <QIcon>

class AvatarWidget : public QWidget
{
    Q_OBJECT
    Q_PROPERTY(QString displayName READ displayName WRITE setDisplayName NOTIFY displayNameChanged)
    Q_PROPERTY(int diameter READ diameter WRITE setDiameter NOTIFY diameterChanged)

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

    // Properties
    QString displayName() const { return m_displayName; }
    void setDisplayName(const QString& name);

    int diameter() const { return m_diameter; }
    void setDiameter(int d);

protected:
    void paintEvent(QPaintEvent* event) override;
    QSize sizeHint() const override { return QSize(m_diameter, m_diameter); }
    QSize minimumSizeHint() const override { return sizeHint(); }

signals:
    void displayNameChanged(const QString& name);
    void diameterChanged(int diameter);

private:
    QPixmap fetchThemeAvatarPixmap(int base) const;
    static QPixmap cropTransparentMargins(const QPixmap& px);
    QPixmap makePlaceholder(int base) const;

private:
    QString m_displayName;
    int m_diameter = 48;
};

#endif // AVATAR_WIDGET_H
