#pragma once

#include <QWidget>
#include <QTextEdit>
#include <QLineEdit>
#include <QPushButton>
#include <QSqlDatabase>

namespace scar {

class ChatWidget : public QWidget {
    Q_OBJECT

public:
    explicit ChatWidget(QWidget* parent = nullptr);
    ~ChatWidget();
    
    void addMessage(const QString& sender, const QString& content, bool isOwnMessage = false);
    void clear();
    
    // Chat history persistence
    void loadHistory();
    void saveMessage(const QString& sender, const QString& content);

signals:
    void messageSent(const QString& content);
    void typingIndicator(bool isTyping);

private slots:
    void onSendClicked();
    void onTextChanged();

private:
    void setupUI();
    void setupDatabase();
    
    QTextEdit* chatDisplay_;
    QLineEdit* messageInput_;
    QPushButton* sendButton_;
    
    QSqlDatabase db_;
    QTimer* typingTimer_;
    bool isTyping_;
};

} // namespace scar
