#ifndef FRAMELESS_DIALOG_H
#define FRAMELESS_DIALOG_H

#include <QDialog>
#include <QVBoxLayout>
#include <QLabel>
#include <QToolButton>
#include <QPoint>
#include <QIcon>

// A reusable dark card-style frameless dialog with:
// - Fixed width (default 464px) [Note: caller can override]
// - Custom header (title + close button) with specified padding 8,16,8,24 (t,r,b,l)
// - Rounded corners (16px) and drop shadow
// - Public bodyLayout() for inserting custom content
class FramelessDialog : public QDialog
{
    Q_OBJECT
public:
    explicit FramelessDialog(const QString& title,
                             int fixedWidth = 464,
                             QWidget* parent = nullptr);

    // Accessors for embedding content
    QVBoxLayout* bodyLayout() const { return m_bodyLayout; }
    QWidget* bodyWidget() const { return m_card; }
    QWidget* bodyContainer() const { return m_bodyWrap; }

    // Update title at runtime
    void setTitle(const QString& title);

    // Show or hide the header bar (title + close button). When hidden, dragging is disabled.
    void setHeaderVisible(bool visible);

protected:
    bool eventFilter(QObject* obj, QEvent* ev) override;

private:
    QWidget* m_card { nullptr };
    QWidget* m_header { nullptr };
    QLabel* m_titleLabel { nullptr };
    QToolButton* m_closeBtn { nullptr };
    QVBoxLayout* m_bodyLayout { nullptr };
    QWidget* m_bodyWrap { nullptr };
    QIcon m_closeIconNormal;
    QIcon m_closeIconHover;

    bool m_dragging = false;
    QPoint m_dragStartPos;
    void applyStyle();
};

#endif // FRAMELESS_DIALOG_H
