#ifndef QDEVITEM_H
#define QDEVITEM_H

#include <config/config.h>
#include <QFrame>
#include <KF5/BluezQt/bluezqt/device.h>
#include <QLabel>
#include <QIcon>
#include <QColor>
#include <QPainter>
#include <QMouseEvent>
#include <QTimer>
#include <QDebug>

#include "config/config.h"

#define TRANSPARENCY_SETTINGS       "org.ukui.control-center.personalise"
#define TRANSPARENCY_KEY            "transparency"

class QDevItem : public QFrame
{
    Q_OBJECT
public:
    enum Status{
        Hover = 0,
        Nomal,
        Click,
    };
    Q_ENUM(Status)

    int FontTable[6] = {32, 30, 26, 24, 23, 22};

    QDevItem(QString address, QStringList deviceinfo, bool connected, QWidget *parent = nullptr);
    ~QDevItem();
    void setFocusStyle(bool val);
    void pressEnterCallback();
    void startIconTimer();

    void InitMemberVariables();
    bool isConnected();

signals:
    void devConnect(bool);

protected:
    void enterEvent(QEvent *);
    void leaveEvent(QEvent *);
    void mousePressEvent(QMouseEvent *);
    void mouseReleaseEvent(QMouseEvent *);
    void paintEvent(QPaintEvent *);

private:
    QMap<QString, QIcon> *typeMap = nullptr;
    QColor getPainterBrushColor();
    QColor getDevStatusColor();
    QPixmap getDevTypeIcon();
    void initMap();
    void DrawBackground(QPainter &);
    void DrawStatusIcon(QPainter &);
    void DrawBattery(QPainter &painter);
    void DrawText(QPainter &);
    void MouseClickedFunc();
    void DevConnectFunc();
    void SendMessage(bool connected);

    Status _MStatus;
    double tran =1;
    bool _clicked;
    bool _pressFlag;
    int iconFlag = 7;
    bool _Connected;
    bool _leaved = false;
    bool _focused = false;

    QTimer        *_iconTimer = nullptr;
    BluezQt::DevicePtr  _MDev = nullptr;
    QString _Address;
    QString _Name;
    QString _Battery;
    QGSettings *StyleSettings = nullptr;
    QGSettings *transparency_gsettings = nullptr;
    QString _MType;

public slots:
    void connectedChangedSlot(bool connected);
};

#endif // QDEVITEM_H
