#pragma once

#include <string>
#include <vector>

#include <QString>
#include <QWidget>

#include "SelectionContext.h"

class ItemChip;
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;
    };

    // The context supplies the icon cache each chip draws its item with
    // (REQ-UI-ITEM-ICON) -- an item with no icon file simply shows no icon, which is not
    // an error -- and what a chip's tooltip reads to explain its item
    // (REQ-UI-ITEM-TOOLTIP).
    explicit ItemChipRow(const SelectionContext& context, QWidget* parent = nullptr);

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

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

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