#pragma once

#include <string>
#include <vector>

#include <QString>
#include <QWidget>

class ItemChip;
class ItemIconCache;
class QGridLayout;

// The buffered items of one building, each as a chip carrying the item's icon, its
// current count and a sub-line (REQ-UI-SINGLE-SELECTION): the per-cycle amount for an
// input, the item's name for an output.
//
// The chips are rebuilt only when the set of items changes, not when their counts do, so
// a refresh at tick rate updates numbers instead of churning widgets.
class ItemChipRow : public QWidget
{
    Q_OBJECT

public:
    struct Entry
    {
        std::string itemId;
        QString     countText;
        QString     subLine;
    };

    // itemIcons is the window-wide per-item icon cache (REQ-UI-ITEM-ICON); an item with
    // no icon file simply shows no icon, which is not an error. Not owned.
    explicit ItemChipRow(ItemIconCache* itemIcons, QWidget* parent = nullptr);

    void setEntries(const std::vector<Entry>& entries);

private:
    void rebuildChips(const std::vector<Entry>& entries);

    ItemIconCache*           m_itemIcons;
    QGridLayout*             m_layout;
    std::vector<std::string> m_itemIds;  // what the chips currently stand for
    std::vector<ItemChip*>   m_chips;
};
