#ifndef ITEM_LIST_SELECTOR_HPP_
#define ITEM_LIST_SELECTOR_HPP_

#include <Item/Item.hpp>
#include <Widget/Widget.hpp>
#include <vector>
#include <functional>

/**
 * Widget for selecting a list of items.
 */
class ItemListSelector : public Widget
{
public:
    typedef std::function<void(int)> RemoveCallback;
    typedef std::function<void(ItemStack)> AddCallback;

private:
    std::vector<ItemStack> &stacks;
    AddCallback onItemAdded;
    RemoveCallback onItemRemoved;

    static constexpr int slotSize = 14;
    static constexpr int numCols = 12;
    static constexpr int minNumRows = 9;

    void drawAddButton(GraphicsContext &context, int x, int y);
    void drawItem(GraphicsContext &context, int x, int y, ItemStack &itemName);
    void openAddFilterPopup(glm::ivec2 pos);

public:
    ItemListSelector(std::vector<ItemStack> &stacks, AddCallback onItemAdded, RemoveCallback onItemRemoved);

    virtual void draw(GraphicsContext &context) override;
    virtual glm::ivec2 getMinSize() override;
    virtual void onMouseUp(Uint8 button) override;
};

#endif