#ifndef BLUETOOTHFILETRANSFERWIDGET_H
#define BLUETOOTHFILETRANSFERWIDGET_H

#include <gio/gio.h>
#include <gio/gfile.h>
#include <gio/gfileinfo.h>
#include <gio/gioerror.h>
#include <KF5/BluezQt/bluezqt/device.h>

#include <QDesktopWidget>
#include <QApplication>
#include <QWidget>
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QByteArray>
#include <QLabel>
#include <QPushButton>
#include <QIcon>
#include <QScrollArea>
#include <QString>
#include <QFont>
#include <QDebug>
#include <QUrl>
#include <QDialog>
#include <QFileInfo>
#include <QPropertyAnimation>
#include <QSequentialAnimationGroup>
#include <QParallelAnimationGroup>
#include <QProgressBar>
#include <QGSettings>
#include <QFontMetrics>
#include <QPainter>
#include <QMessageBox>
#include <QAbstractAnimation>
#include <QTreeWidget>
#include <QKeyEvent>
#include "config/config.h"

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

class BluetoothFileTransferWidget : public QWidget
{
    Q_OBJECT
public:
    enum Status {
        /** Indicates that the transfer is queued. */
        Queued,
        /** Indicates that the transfer is active. */
        Active,
        /** Indicates that the transfer is suspended. */
        Suspended,
        /** Indicates that the transfer have completed successfully. */
        Complete,
        /** Indicates that the transfer have failed with error. */
        Error,
        /** Indicates that the transfer status is unknown. */
        Unknown
    };
    Q_ENUM(Status)

    explicit BluetoothFileTransferWidget(QStringList files, QMap<QString, QStringList> devicelist, QString dev_address = "");
    ~BluetoothFileTransferWidget();

    typedef enum _SEND_DATA_STATE
    {
        _SEND_NONE = 0,
        _SEND_ACTIVE,
        _SEND_COMPLETE,
        _SENDING,
        _SEND_FAILURE

    }SEND_DATA_STATE;

    static bool isShow;

    void Get_fie_type(int i);
    void initFileInfo();
    void Get_file_size(float);
    void Initialize_and_start_animation();
    void init_m_progressbar_value(quint64);
    void tranfer_error();
    void initTransferPath(QString path, bool isSend);
    void insertNewFileList(QStringList fileList);

    int  get_send_data_state();

signals:
    void sender_dev_name(QString, QString);
    void close_the_pre_session();
    void continueSendFiles(QString);
public slots:
    void onClicked_OK_Btn();
    void set_m_progressbar_value(quint64, QString);
    void get_transfer_status(QString, QString, QString);
    void GSettingsChanges(const QString &key);

private:
    bool is_Intel = false;

    double tran =1;
    int fileNums    = 0;
    int active_flag = 2;
    int pressTabCnt = 0;
    int pressUDCnt  = 0;

    QGSettings *GSettings              = nullptr;
    QGSettings *transparency_gsettings = nullptr;

    QLabel *tip_text             = nullptr;
    QLabel *title_icon           = nullptr;
    QLabel *title_text           = nullptr;
    QLabel *target_icon          = nullptr;
    QLabel *target_name          = nullptr;
    QLabel *target_size          = nullptr;
    QLabel *Tiptop               = nullptr;
    QLabel *transNum             = nullptr;
    QLabel *tranfer_status_icon  = nullptr;
    QLabel *tranfer_status_text  = nullptr;

    quint64 m_curr_filesize;

    QTreeWidget *qtw = nullptr;

    QParallelAnimationGroup *main_animation_group = nullptr;

    QProgressBar *m_progressbar = nullptr;

    QPushButton *close_btn   = nullptr;
    QPushButton *cancel_btn  = nullptr;
    QPushButton *ok_btn      = nullptr;
    QPushButton *selectedBtn = nullptr;

    QTreeWidgetItem *selectedItem = nullptr;

    QList<QIcon>   file_icon;
    QList<QString> file_size;
    QList<quint64> _filesize;
    QList<QString> filetype;

    QString dev_name;
    QString _objectPath;

    QStringList selectedFiles;

    SEND_DATA_STATE send_state = _SEND_NONE;

    QTreeWidgetItem* selectedDev = nullptr;
    QList<QTreeWidgetItem*> toolbutton_list;
    QMap<QTreeWidgetItem*, QString> itemMap;
    void initLayout();
    void initIntelLayout();
    QRect getButton();
    void initQTreeWidget(QMap<QString, QStringList> devicelist, QString dev_address);

protected:
    void paintEvent(QPaintEvent *event);
    void keyPressEvent(QKeyEvent *event);
};

#endif // BLUETOOTHFILETRANSFERWIDGET_H
