#pragma once

#include <optional>
#include <vector>

#include <QString>

#include "ModalDialog.h"

class QHBoxLayout;
class QLabel;

// The game's own message box (REQ-UI-MODAL-CHROME): a title, an optional line or two of
// text, and a row of buttons the caller names. It stands in for QMessageBox at the three
// places the player is asked to decide something -- the escape menu (REQ-UI-GAME-MENU)
// and the game-over and win screens (REQ-HQ-GAME-OVER, REQ-WIN-SCREEN) -- so that those
// read as part of the game rather than as system alerts.
//
// The caller identifies buttons by the index addButton() hands back, and asks
// getClickedButtonIndex() afterwards; the QDialog result code says only whether a button
// was clicked at all. Q and a click outside do not dismiss it: every button here is a
// decision, and there is no "no change" among them to fall back on.
class MessageDialog : public ModalDialog
{
    Q_OBJECT

public:
    // text may be empty, for a dialog that is a question its buttons already state.
    MessageDialog(const QString& title, const QString& text, QWidget* parent = nullptr);

    // Appends a button and returns its index, left to right.
    int addButton(const QString& caption);

    // Which button Escape stands for. Without one, Escape does nothing -- a dialog whose
    // buttons all commit to something has no dismissal to offer.
    void setEscapeButtonIndex(int index);

    std::optional<int> getClickedButtonIndex() const;

public slots:
    void reject() override;

private:
    void onButtonClicked(int index);

    QHBoxLayout*       m_buttonLayout;
    int                m_buttonCount;
    std::optional<int> m_escapeButtonIndex;
    std::optional<int> m_clickedButtonIndex;
};
