#ifndef CMSGPANE_H
#define CMSGPANE_H

#include <QWidget>
#include <QTimer>
#include <QWebEngineView>
#include <QTextEdit>
#include <QLabel>
#include <QJsonParseError>
#include <QJsonObject>
#include <QJsonArray>
#include <QDesktopWidget>
#include <QApplication>
#include <QMenuBar>
#include <QToolButton>
#include <QAction>
#include <QDebug>
#include <QMenu>
#include <QSystemTrayIcon>
#include <QPushButton>
#include <QDBusInterface>
#include <QDBusReply>
#include <QDBusObjectPath>
#include <QImage>
#include <QByteArray>
#include <QBuffer>
#include <QWebChannel>
#include <QDateTime>
#include <QDir>
#include <unistd.h>

#include "kasendbar.h"
#include "channelmessage.h"
#include "startuptools.h"
#include "ctrl.h"
#include "recorder.h"
#include "runtimerecorder.h"
#include "meetingrecorder.h"

class ChatOperator;
class CPushButtonEx;
class Recorder;
class RuntimeRecorder;
class MeetingRecorder;

class CMsgPane : public QWidget
{
    Q_OBJECT
public:
    explicit CMsgPane(QWidget *parent = 0);

public slots:
    //返回主页
    void onBackBtnClicked();
    void onUrlChanged(const QUrl &url);
    //消息
    void onClearMsg();
    void onSendMsg(const QString &msgHead, const QString &msg);
    void onRecvMsg(QString msg, bool is_end, int index);
    void onSaveMessageList();
    void onLoadMessageList();
    //会话
    void saveDialog();
    void clearDialog();
    void onShowText(const QString text);
    void onShowSpeech(const QString text);
    void OnWebViewLoaded();
    void userAccountsChanged();
    void loadPlugin(QString pluginHtmlFile);
    //发送整段语音
    void onSendAudio();
    void onStopAudio();
    //发送实时语音
    void onSendRuntimeAudio(QString lan, QString target);
    void onStopRuntimeAudio();
    //发送会议录音
    void onSendMeetingAudio();
    void onPauseMeetingAudio();
    void onStopMeetingAudio();
    //语音听写
    void onClearDictation();
    void onCopyDictation();
    //发言人重命名
    void onRename(QString originalName);
    //会议列表
    void onMeetingList(QString str);
    //处理会议原文
    void processMessageList(QString jsonStr);
    void onGenerateSummary(QString msg, bool is_end, int index);

    void onUpdateReply(const QString &msgHead, const QString &msg);
    void onStopReply();

private:
    void createAllChildWnd();
    void initCtrl();
    void initSolts();
    void relayout();
    void sendGetRequest(QString strMsg);
    void initChatOperator();
    void initBubbleUpdateTimer();
    void initCurrentUserName();
    void initCurrentUserIcon();
    void pushMsg(QString func, QString msgHead, QString msg);
    void saveDialogToFile(const QString &dialogJsonString);
    void saveMessageToFile(const QString &msgJsonString);
    void saveMeetingToFile();

signals:
    void sigSetup();
    void sigSaveDialog(QString filePath);
    void sigUrlChanged(const QUrl &url);

private slots:
    void updateBubble();
    void updateModelStatus();

private:
    QWebChannel *m_channel = nullptr;
    ChannelMessage *m_channelMsg = nullptr;
    QWebEngineView *m_pViewChat = nullptr;
    //CTextEditEx *m_textEdit;
    KASendBar *m_sendBar = nullptr;
    QPushButton *m_buttonSetup = nullptr;
    Recorder *m_recorder = nullptr;
    RuntimeRecorder *m_runtimeRecorder = nullptr;
    MeetingRecorder *m_meetingRecorder = nullptr;

    CPushButtonEx *m_btnMore = nullptr;
    CPushButtonEx *m_btnVoice = nullptr;
    QLabel *m_labSeparatorLine = nullptr;
    QAction *confAction = nullptr;
    //NLP语言模型
    ChatOperator *m_chatOperator = nullptr;
    //返回消息
    bool new_reply = true;
    QString recv_message;
    int bubble_show_count;
    uint loading_dot_index;
    QTimer *bubble_update_timer = nullptr;
    //会议
    QString m_summary;
    QString m_origin;
};

#endif // CMSGPANE_H
