#pragma once

#include <memory>

#include "BuildingBlocksChangedEvent.h"
#include "EventHandler.h"
#include "ExpansionCostChangedEvent.h"
#include "ItemTooltipContext.h"
#include "OptionButton.h"

class QLabel;

// The asteroid expansion button (REQ-UI-EXPAND-BUTTON): a button that stands in the game
// world on the columns the next purchase would unlock, rather than in the header bar.
//
// It knows what it says and what it costs; where it stands is MainWindow's to decide, the
// position being a place in the world and this button knowing nothing of the view's scroll
// (MainWindow::placeExpandButton).
//
// Its face is two lines, `Expand` over the cost, so that the cost is a display naming an
// item and can explain it the way every other item value does -- on hover only, the click
// belonging to the button (REQ-UI-ITEM-VALUE-TOOLTIP).
class ExpandButton : public OptionButton,
                     public CombinedEventHandler<ExpansionCostChangedEvent,
                                                 BuildingBlocksChangedEvent>
{
    Q_OBJECT

public:
    // Nothing in the context is owned; all of it must outlive this widget.
    explicit ExpandButton(const ItemTooltipContext& context, QWidget* parent = nullptr);
    ~ExpandButton() override;

private:
    void handleEvent(std::shared_ptr<const ExpansionCostChangedEvent> event) override;
    void handleEvent(std::shared_ptr<const BuildingBlocksChangedEvent> event) override;

    // Re-states the cost and whether the player can pay it. Asks for a fresh placement
    // pass afterwards, because a wider cost re-centers the button.
    void refresh();

    ItemTooltipContext m_context;
    QLabel*            m_costLabel;
};
