#pragma once

#include <string>
#include <vector>

#include <QWidget>

class ItemIconCache;
class QHBoxLayout;

// What one production cycle does, on a line: each input item with its per-cycle amount,
// an arrow, each output with its amount, and the cycle time
// (REQ-UI-RECIPE-SUMMARY). It restates the selected recipe without the player having to
// open the selection dialog, and it is the panel's only display of the cycle time.
class RecipeSummaryRow : public QWidget
{
    Q_OBJECT

public:
    struct Amount
    {
        std::string itemId;
        int         amount = 0;

        bool operator==(const Amount& other) const
        {
            return itemId == other.itemId && amount == other.amount;
        }
    };

    // itemIcons is the window-wide per-item icon cache (REQ-UI-ITEM-ICON); an item with
    // no icon file falls back to its id. Not owned.
    explicit RecipeSummaryRow(ItemIconCache* itemIcons, QWidget* parent = nullptr);

    // Hides the row when there is nothing selected to produce, which is how a building
    // with no recipe shows no summary at all.
    void setSummary(const std::vector<Amount>& inputs,
                    const std::vector<Amount>& outputs, double durationSeconds);

private:
    void rebuild(const std::vector<Amount>& inputs, const std::vector<Amount>& outputs,
                 double durationSeconds);
    void addAmounts(const std::vector<Amount>& amounts);

    ItemIconCache*      m_itemIcons;
    QHBoxLayout*        m_layout;
    // What the row currently shows, so a refresh at tick rate rebuilds it only when the
    // recipe actually changed.
    std::vector<Amount> m_inputs;
    std::vector<Amount> m_outputs;
    double              m_durationSeconds = -1.0;
};
