#pragma once

#include <vector>

#include "ItemTooltipContext.h"
#include "ModalDialog.h"
#include "SchematicChoiceOption.h"

struct RecipesConfig;

// The drop's choice dialog (REQ-DEF-SCHEMATIC-DROP). Unlike every other dialog it cannot
// be dismissed: clicking an option is the only way out, so getChosenIndex() always names
// an option the player picked, and it only ever finishes Accepted. It inherits the base's
// refusal of Q and of a click outside (ModalDialog::isDismissible) and adds the refusal
// of Escape below.
class SchematicChoiceDialog : public ModalDialog
{
    Q_OBJECT

public:
    // The context's icon caches draw the recipe lines of the "Unlocks recipes" list
    // (REQ-DEF-SCHEMATIC-DROP, REQ-UI-ITEM-ICON, REQ-UI-BUILD-ICON), and the rest of it
    // lets the items those lines name explain themselves (REQ-UI-ITEM-VALUE-TOOLTIP).
    // Nothing in it is owned.
    SchematicChoiceDialog(const std::vector<SchematicChoiceOption>& options,
                          const RecipesConfig& recipes,
                          const ItemTooltipContext& context,
                          QWidget* parent = nullptr);

    int getChosenIndex() const;

public slots:
    // Refuses the dismissal (REQ-DEF-SCHEMATIC-DROP): the drop is a reward the player
    // has earned, and leaving without choosing would either forfeit it or award the
    // option that happens to be first. Escape funnels through QDialog::reject(), so
    // declining it here turns it away without swallowing keys one at a time.
    void reject() override;

private:
    void onOptionClicked(int index);

    int m_chosenIndex;
};
