package jesse.keeblarcraft.gui.ShopKeeperGUI;

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

public class NewItemButton extends ClickableLayer {
    private static final Identifier NEW_ITEM_MENU = new Identifier(Keeblarcraft.MOD_ID, "textures/gui/shopkeeper_item_slot.jpeg"); /// TODO: Does not exist
    private static NewItemMenu newItemMenu;

    public NewItemButton(Identifier texture, Text layerName, int width, int height, int startX, int startY) {
        super(texture, layerName, width, height, startX, startY);

        // These values may be temporary
        newItemMenu = new NewItemMenu(NEW_ITEM_MENU, Text.of("add_item_menu"), 32, 24, this.getX() + 20, this.getY() + 20);
    }

    @Override
    public void onClick(double x, double y) {
        // Toggle the menu sub layer to be on if it was clicked. @See UpdateSubLayers for when it gets closed
        System.out.println("Status of new item menu: " + newItemMenu.IsOpen());
        if (!newItemMenu.IsOpen()) {
            System.out.println("Adding new item menu and telling it to open");
            this.AddSubLayer(newItemMenu);
            newItemMenu.OpenMenu();
        }
    }

    @Override
    public void UpdateSubLayers() {
        if (!newItemMenu.IsOpen()) {
            this.ClearSubLayers();
        }
    }

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