package com.r3944realms.modernlifepatch.mixin.screen;

import com.dairymoose.modernlife.blocks.gui.chess.*;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.network.chat.Component;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@Mixin(ChessScreen.class)
public abstract class MixinChessBoardScreen extends Screen {
    @Shadow(remap = false) public abstract int boardXtoScreenX(int boardX);

    @Shadow(remap = false) public abstract int boardYtoScreenY(int boardY);

    protected MixinChessBoardScreen(Component component) {
        super(component);
    }


    @Inject(method = "showTooltipForPiece",at = @At("HEAD"), cancellable = true, remap = false)
    private void showTooltipForPiece(GuiGraphics graphics, Piece p, CallbackInfo ci) {
        String pieceNameKey = "modernlifepatch.lang.chess.modernlifepatch.";
        if (p instanceof RookPiece) {
            pieceNameKey += "rook";
        } else if (p instanceof BishopPiece) {
            pieceNameKey += "bishop";
        } else if (p instanceof PawnPiece) {
            pieceNameKey += "pawn";
        } else if (p instanceof KnightPiece) {
            pieceNameKey += "knight";
        } else if (p instanceof KingPiece) {
            pieceNameKey += "king";
        } else if (p instanceof QueenPiece) {
            pieceNameKey += "queen";
        } else {
             pieceNameKey = "modernlifepatch.unknown";
        }

        graphics.renderTooltip(Minecraft.getInstance().font, Component.translatable(pieceNameKey), boardXtoScreenX(p.x), boardYtoScreenY(p.y));
        ci.cancel();
    }
}
