package jesse.keeblarcraft.gui.ShopKeeperGUI;

import jesse.keeblarcraft.Keeblarcraft;
import jesse.keeblarcraft.gui.Generics.ClickableLayer;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.gui.screen.narration.NarrationMessageBuilder;
import net.minecraft.item.ItemStack;
import net.minecraft.text.Text;
import net.minecraft.util.Identifier;

// All the custom content that a store item will have. Handled by @see MerchandiseScroller.java
public class DrawableStoreItem extends ClickableLayer {
    // Names are hard. ITEM_ICON is the actual SLOT icon itself; not the in-game item!!!!
    private static final Identifier ITEM_ICON = new Identifier(Keeblarcraft.MOD_ID, "textures/gui/shopkeeper_item_slot.png");
    private Integer itemCost;
    private String itemName;
    private Integer amountSelected = 0;
    ItemStack itemTextureId;

    public DrawableStoreItem(String itemName, Integer itemCost, ItemStack itemTextureId) {
        this(itemName, itemCost, Text.of(""), 85, 50);
        this.itemTextureId = itemTextureId;
    }

    public DrawableStoreItem(String itemName, Integer itemCost, Text layerName, int width, int height) {
        super(ITEM_ICON, layerName, width, height, 0, 0);
        this.itemCost = itemCost;
        this.itemName = itemName;
    }

    public Integer GetPrice() {
        return this.itemCost;
    }

    public String GetName() {
        return this.itemName;
    }

    public void Add() {
        ++this.amountSelected;
        System.out.println("Current buy amount: " + this.amountSelected);
    }

    @Override
    public void renderButton(DrawContext context, int mouseX, int mouseY, float delta) {
        super.renderButton(context, mouseX, mouseY, delta);

        // Now we want to draw the item icon in the icon slot
        if (this.itemTextureId != null) {
            context.drawItem(this.itemTextureId, this.getX() + 13, this.getY() + 22); // TODO: Need to correct offest to draw
        } else {
            // TODO: Add default icon to draw if no texture is set or could be found for item
        }
    }

    public void Subtract() {
        --this.amountSelected;
        System.out.println("Current buy amount: " + this.amountSelected);
    }

    public Integer GetTotal() {
        return this.amountSelected * itemCost;
    }

    @Override
    public void onClick(double x, double y) {
        System.out.println("User clicked the following coordinates: [" + x + ", " + y + "]");
    }

    @Override
    protected void appendClickableNarrations(NarrationMessageBuilder builder) {}
}
