package com.acethewildfire.acesbs.screen.custom;

import com.acethewildfire.acesbs.AcesBS;
import com.mojang.blaze3d.systems.RenderSystem;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.gui.screen.ingame.HandledScreen;
import net.minecraft.client.render.GameRenderer;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.text.Text;
import net.minecraft.util.Identifier;

public class EntropicEntanglerScreen extends HandledScreen<EntropicEntanglerScreenHandler> {

    public static final Identifier GUI_TEXTURE =
            Identifier.of(AcesBS.MOD_ID, "textures/gui/entropic_entangler/entropic_entangler_gui.png");
    public static final Identifier ENTANGLE_LEFT_TEXTURE =
            Identifier.of(AcesBS.MOD_ID, "textures/gui/entangle_left_progress.png");
    public static final Identifier ENTANGLE_RIGHT_TEXTURE =
            Identifier.of(AcesBS.MOD_ID, "textures/gui/entangle_right_progress.png");

    public EntropicEntanglerScreen(EntropicEntanglerScreenHandler handler, PlayerInventory inventory, Text title) {
        super(handler, inventory, title);
    }

    @Override
    protected void drawBackground(DrawContext context, float delta, int mouseX, int mouseY) {
        RenderSystem.setShader(GameRenderer::getPositionTexProgram);
        RenderSystem.setShaderColor(1f, 1f, 1f, 1f);
        RenderSystem.setShaderTexture(0, GUI_TEXTURE);

        int x = (width - backgroundWidth) / 2;
        int y = (height - backgroundHeight) / 2;

        context.drawTexture(GUI_TEXTURE, x, y, 0, 0, backgroundWidth, backgroundHeight);

//        renderProgressArrow(context, x, y);
        renderEntangleProgress(context, x, y);
    }

//    private void renderProgressArrow(DrawContext context, int x, int y) {
//
//        if(handler.isCrafting()) {
//            context.drawTexture(ARROW_TEXTURE, x + 79, y + 35, 0, 0,
//                    handler.getScaledArrowProgress(), 16, 24, 16);
//        }
//    }

    private void renderEntangleProgress(DrawContext context, int x, int y) {
        if(handler.isCrafting()) {
            context.drawTexture(ENTANGLE_LEFT_TEXTURE, x + 52, y + 25, 0, 0,
                    handler.getScaledEntangleProgress(), 9, 37, 9);
            context.drawTexture(ENTANGLE_RIGHT_TEXTURE, x + 89 + (37 - handler.getScaledEntangleProgress()), y + 52, (37 - handler.getScaledEntangleProgress()), 0,
                    handler.getScaledEntangleProgress(), 9, 37, 9);
        }
    }

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

}
