package com.acethewildfire.acesbs.compat;

import com.acethewildfire.acesbs.AcesBS;
import com.acethewildfire.acesbs.block.ModBlocks;
import com.acethewildfire.acesbs.item.ModItems;
import me.shedaniel.math.Point;
import me.shedaniel.math.Rectangle;
import me.shedaniel.rei.api.client.gui.Renderer;
import me.shedaniel.rei.api.client.gui.widgets.Widget;
import me.shedaniel.rei.api.client.gui.widgets.Widgets;
import me.shedaniel.rei.api.client.registry.display.DisplayCategory;
import me.shedaniel.rei.api.common.category.CategoryIdentifier;
import me.shedaniel.rei.api.common.display.basic.BasicDisplay;
import me.shedaniel.rei.api.common.entry.EntryIngredient;
import me.shedaniel.rei.api.common.util.EntryStacks;
import net.minecraft.text.Text;
import net.minecraft.util.Identifier;

import java.util.LinkedList;
import java.util.List;

public class EntropicEvisceratorCategory implements DisplayCategory<BasicDisplay> {
    public static final Identifier GUI_TEXTURE =
            Identifier.of(AcesBS.MOD_ID, "textures/gui/entropic_eviscerator/entropic_eviscerator_gui_rei.png");

    public static final CategoryIdentifier<EntropicEvisceratorDisplay> ENTROPIC_EVISCERATOR =
            CategoryIdentifier.of(AcesBS.MOD_ID, "entropic_eviscerator");

    @Override
    public CategoryIdentifier<? extends BasicDisplay> getCategoryIdentifier() {
        return ENTROPIC_EVISCERATOR;
    }

    @Override
    public Text getTitle() {
        return Text.translatable("block.acesbs.entropic_eviscerator");
    }

    @Override
    public Renderer getIcon() {
        return EntryStacks.of(ModBlocks.ENTROPIC_EVISCERATOR.asItem().getDefaultStack());
    }

    @Override
    public List<Widget> setupDisplay(BasicDisplay display, Rectangle bounds) {
        Point startPoint = new Point(bounds.getCenterX() - 87, bounds.getCenterY() - 41);
        List<Widget> widgets = new LinkedList<>();

        widgets.add(Widgets.createTexturedWidget(GUI_TEXTURE, new Rectangle(startPoint.x, startPoint.y, 175, 82)));

        widgets.add(Widgets.createSlot(new Point(startPoint.x + 80, startPoint.y + 17)).entries(display.getInputEntries().get(0)).markInput());
        widgets.add(Widgets.createSlot(new Point(startPoint.x + 8, startPoint.y + 17)).entries(EntryIngredient.of(EntryStacks.of(ModItems.STABLE_ENTROPY))));
        widgets.add(Widgets.createSlot(new Point(startPoint.x + 80, startPoint.y + 53)).entries(display.getOutputEntries().get(0)).markOutput());

        return widgets;
    }

    @Override
    public int getDisplayHeight() {
        return 90;
    }
}
