#pragma once

#include <QWidget>
#include <QTreeView>
#include <QHeaderView>
#include <QSortFilterProxyModel>
#include <QVBoxLayout>
#include <QPushButton>
#include <QLabel>
#include <QLineEdit>
#include <QCheckBox>
#include <QHBoxLayout>
#include <QComboBox>

#include "ui/models/EmailListModel.h"
#include "ui/models/EmailTreeModel.h"

class MailListView : public QWidget {
    Q_OBJECT

public:
    explicit MailListView(QWidget *parent = nullptr);
    ~MailListView() override = default;

    void setModel(EmailListModel *model);
    QTreeView* treeView() const { return m_treeView; }

signals:
    void emailSelected(int mailId);
    void emailOpenRequested(int mailId);
    void composeRequested();

private slots:
    void onRowSelected(const QModelIndex &index);
    void onSearchTextChanged(const QString &text);
    void onFilterChanged();
    void onGroupByChanged(int index);

private:
    void setupUI();
    void refreshTreeModel();

    QTreeView *m_treeView;
    EmailTreeModel *m_treeModel;
    QSortFilterProxyModel *m_proxyModel;
    EmailListModel *m_sourceModel = nullptr;
    QPushButton *m_composeButton;
    QLineEdit *m_searchEdit;
    QCheckBox *m_unreadOnlyCheck;
    QCheckBox *m_flaggedOnlyCheck;
    QCheckBox *m_hasAttachmentsCheck;
    QComboBox *m_groupByCombo;
};