#ifndef FRAMELESSBASE_H
#define FRAMELESSBASE_H

#include <QWidget>

#include <QMainWindow>
#include <QMenuBar>
#include <QMessageBox>
#include <QDialog>

class QVBoxLayout;
class QEventLoop;
class QCloseEvent;

namespace QWK {
class WidgetWindowAgent;
class StyleAgent;
} // namespace QWK

class TMainWindow : public QMainWindow
{
    Q_OBJECT
public:
    explicit TMainWindow(QWidget *parent = nullptr);
    ~TMainWindow() override {}

protected:
    bool event(QEvent *event) override;

private:
    void installWindowAgent();
    QWK::WidgetWindowAgent *windowAgent;
};

class TWidget : public QWidget
{
    Q_OBJECT
public:
    explicit TWidget(QWidget *parent = nullptr);
    QWidget *menuWidget() const;
    void setMenuWidget(QWidget *widget);
    QVBoxLayout *mainLayout() const { return m_mainLayout; }

protected:
    bool event(QEvent *event) override;
    void installWindowAgent();

protected:
    QWK::WidgetWindowAgent *windowAgent = nullptr;
    QWidget *m_menuWidget = nullptr;
    QVBoxLayout *m_mainLayout = nullptr;
};

// 轻量对话框基类：继承 QDialog，并复用与 TWidget 一致的无边框窗口代理/标题栏能力
class TDialog : public QDialog
{
    Q_OBJECT
public:
    enum DialogCode { Rejected = QDialog::Rejected, Accepted = QDialog::Accepted };

    explicit TDialog(QWidget *parent = nullptr);
    ~TDialog() override = default;

    QWidget *menuWidget() const;
    void setMenuWidget(QWidget *widget);
    QVBoxLayout *mainLayout() const { return m_mainLayout; }

public slots:
    void accept() override;  // 包装到 QDialog::accept()
    void reject() override;  // 包装到 QDialog::reject()

protected:
    bool event(QEvent *event) override;
    void installWindowAgent();

private:
    QWK::WidgetWindowAgent *windowAgent = nullptr;
    QWidget *m_menuWidget = nullptr;
    QVBoxLayout *m_mainLayout = nullptr;
};

#endif // FRAMELESSBASE_H
