#pragma once
#include <QMutex>
#include <QStringList>
#include <QTimer>
#include <QWaitCondition>
#include <QWidget>
#include "qobjectdefs.h"

class QSplitter;

class UserProfileWidget;
class ChatWindow;

class WebSocketClient;
class StatsWidget;
class AudioDeviceSelectorIcon;
class AudioDeviceSelectorIconDecoupled;

namespace ADS {
    class DockManager;
    class DockWidget;
}

class MainPanel : public QWidget
{
    Q_OBJECT
public:
    explicit MainPanel(QWidget *parent = nullptr);
    ~MainPanel();
    void setRole(const QStringList &roleList);

    void setPushRoomId(const QString &room);



signals:
    void logoutClicked();

public slots:

private:
    void setPlayerWidget(QWidget *newPlayer);

    void handleDebouncedPlay(); // 防抖处理函数

private:
    QSplitter *splitter = nullptr;
    QWidget *playerContainer = nullptr;
    QWidget *playerWidget = nullptr;
    UserProfileWidget *userProfile = nullptr;
    ChatWindow *chatView = nullptr;

    WebSocketClient *webSocketClient = nullptr;
    StatsWidget *statsWidget = nullptr;
    bool m_isStartingPlay = false;
    QMutex m_playMutex;
    QWaitCondition m_playCond;
    QTimer *m_debounceTimer = nullptr;
    QString m_pendingRoomId;

    class PopoverButtonGroup *buttonGroup;
    AudioDeviceSelectorIcon *m_audioDeviceSelector = nullptr;
    AudioDeviceSelectorIconDecoupled *m_audioDeviceSelectorDecoupled = nullptr;

    // DockManager 相关
    ADS::DockManager *m_dockManager = nullptr;
    
private slots:
    void initAudioDeviceSelectors();
};
