#ifndef LOCKWIDGET_H
#define LOCKWIDGET_H

#include <QWidget>
#include <QObject>
#include "userinfo.h"

class QListWidgetItem;
class MyListWidget;
class QPushButton;
class QPixmap;
class LockDialogModel;
class UserListWidget;
class SessionListWidget;
class AuthDialog;
class MyNetworkWidget;
class PowerListWidget;
class TimeWidget;
class BatteryWidget;
class VirtualKeyboardWidget;
class BlockWidget;
class StatusButton;
class NetWorkButton;

class LockWidget : public QWidget
{
    Q_OBJECT
public:
    explicit LockWidget(LockDialogModel *model, QWidget *parent = nullptr);
    bool exitSubWidget();
    void stopAuth();
    void startAuth();
protected:
    void paintEvent(QPaintEvent *event);
    bool eventFilter(QObject *obj, QEvent *event);
    void resizeEvent(QResizeEvent *event);
    void keyReleaseEvent(QKeyEvent *e);

signals:

private:
    void initUI();
    void initConnections();
    void initUserWidget();
    void initSessionWidget();
    void initPowerWidget();
    void initButtonWidget();
    void initTimeWidget();
    void initBlockWidget();
    void sendNetPluginVisible(bool visible);

    /**
     * @brief 获取usd快捷键键值：QString
     *
     */
    void initUsdMediaKeys();
    /**
     * @brief 快捷键转化：QString - QKeySequence
     * @param shortcuts   快捷键键值
     * @return QKeySequence
     */
    static const QKeySequence listFromString(QString shortcuts);

    void updateBottomButton();

    void SwitchToUser(QString strUserName);

private Q_SLOTS:
    /**
     * @brief item选中状态改变
     * @param current 前一个选中item
     *        previous 当前选中item
     * @return
     */
    void onPowerItemChanged(QListWidgetItem *current, QListWidgetItem *previous);
    void onButtonItemChanged(QListWidgetItem *current, QListWidgetItem *previous);
    /**
     * @brief item点击响应
     * @param item
     * @return
     */
    void onButtonItemClicked(QListWidgetItem *item);
    void onPowerItemClicked(QListWidgetItem *item);

    void onUsersInfoChanged();
    void onCurUserChanged(const QString &strUserName);
    void onSessionChanged(const QString &strSession);
    void onUserChangedByManual(const QString &userName);

    void onUsdMediaKeysChanged(const QString &keys, const QString &value);

    void onShowSessionListWidget();
    void onShowBatteryWidget();
    void onShowUserListWidget();
    void onShowNetworkWidget();
    void onShowPowerListWidget();
    void onShowVirtualKeyboard();

    void onNetWorkResetLocation();
    void onSetVirkeyboardPos();
    void onHideVirkeyboard();

    void onShowInhibitWarning(QStringList list, int type);

    void onMulUsersLogined(QString inhibitType);

    void onConfirmBtnClicked();
    void onCancelBtnClicked();
    /**
     * @brief onCustomRequestAccount 请求切换认证用户
     * @param account 用户名
     */
    void onCustomRequestAccount(QString account);
    /**
     * @brief onGetCustomPluginMsg 获取插件消息槽
     * @param strMsg 消息json
     */
    void onGetCustomPluginMsg(QString strMsg);

    void onSessionActiveChanged(bool isActive);

Q_SIGNALS:
    void authSucceed(QString strUserName);

private:
    //  日期时间
    TimeWidget *m_timeWidget = nullptr;
    //  用户列表
    UserListWidget *m_userListWidget = nullptr;
    // 会话列表
    SessionListWidget *m_sessionListWidget = nullptr;
    //  电源管理列表
    PowerListWidget *m_powerListWidget = nullptr;
    //  底部button列表
    MyListWidget *buttonListWidget = nullptr;

    QPixmap background;

    LockDialogModel *m_modelLockDialog = nullptr;

    UserInfo m_curUserInfo;

    AuthDialog *authDialog = nullptr;
    QTimer *m_timerChkActive = nullptr;

    // usd快捷键键值
    QString m_areaScreenShot;
    QString m_areaScreenShot2;
    QString m_screenShot;
    QString m_screenShot2;
    QString m_windowScreenshot;

    MyNetworkWidget *m_networkWidget = nullptr;
    BatteryWidget *batteryWidget = nullptr;
    VirtualKeyboardWidget *m_virtualKeyboardWidget = nullptr;
    BlockWidget *m_blockWidget = nullptr;
    QString m_inhibitType;

    // 底部button
    StatusButton *m_sessionButton = nullptr;
    QListWidgetItem *m_btnItemSession = nullptr;
    StatusButton *m_batteryonButton = nullptr;
    StatusButton *m_userButton = nullptr;
    QListWidgetItem *m_btnItemUser = nullptr;
    NetWorkButton *m_networkButton = nullptr;
    StatusButton *m_virKbButton = nullptr;
    StatusButton *m_powerManagerButton = nullptr;

    bool m_isCustomDefault = false;         /** 是否默认使用第三方认证 */
    bool m_isShowNetwork = true;            /** 是否显示网络插件 */
    bool m_isShowUserSwitch = true;         /** 是否显示用户切换 */
};

#endif // LOCKWIDGET_H
