#pragma once

#include <Either.h>
#include <UIMLView.h>
#include <VecN.h>

#include "InventoryView.h"
#include "NetworkAPIProcessor.h"

class CraftingGridElement : public Framework::UIMLElement
{
public:
    CraftingGridElement();
    //! prüft, ob dieses UIML Element für ein bestimmtes xml Element zuständig
    //! ist
    bool isApplicableFor(Framework::XML::Element& element) override;
    //! erstellt eine neue Drawable zu einem gegebenen xml Element
    Framework::Drawable* parseElement(Framework::XML::Element& element,
        Framework::UIMLContainer& generalFactory) override;
    bool updateElement(Framework::XML::Element& element,
        Framework::Drawable& z,
        Framework::UIMLContainer& generalFactory) override;
    //! wendet die layout parameter zu einer Drawable an
    void layout(Framework::XML::Element& element,
        Framework::Drawable& z,
        int pWidth,
        int pHeight,
        Framework::UIMLContainer& generalLayouter) override;
};

class CraftingGridView : public Framework::DrawableBackground,
                         public NetworkAPIProcessor,
                         public InventoryDragSource
{
private:
    int rowSize;
    int colSize;
    int numOutputSlots;
    // entity id or block position
    int* address;
    int addressLength;
    Framework::Array<SlotInfo>* slots;
    Framework::Array<SlotInfo>* outputs;
    Framework::Text id;
    Framework::Point mausPos;
    int dragStartId;
    int dragStopId;
    Framework::Button* craft;
    Framework::Button* recipies;
    int currentTooltipSlot;
    int requestetTooltipSlot;
    int getSlotByLocalPos(Framework::Point pos);

public:
    CraftingGridView(Framework::Text id,
        int rowSize,
        int colSize,
        int numOutputSlots,
        int* address,
        int addressLength);
    ~CraftingGridView();
    void api(char* message) override;
    bool tick(double tickVal) override;
    void render(Framework::Image& rObj) override;
    void doMouseEvent(Framework::MouseEvent& me, bool userRet) override;
    Framework::Either<int, Framework::VecN<int, 4>>
    getInventoryTarget() const override;
};