package com.tiedup.remake.client.gui.widgets;

import com.tiedup.remake.client.gui.util.GuiColors;
import net.minecraft.ChatFormatting;
import net.minecraft.client.gui.Font;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.network.chat.Component;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;

/**
 * Shared rendering utilities for cell list screens (CellManagerScreen, CellSelectorScreen).
 * Extracts duplicated rendering logic for empty states and count badges.
 */
@OnlyIn(Dist.CLIENT)
public final class CellListRenderer {

    private CellListRenderer() {
        // Utility class — no instantiation
    }

    /**
     * Renders a two-line empty state message centered in the list area.
     *
     * @param graphics   the graphics context
     * @param font       the font renderer
     * @param centerX    horizontal center of the list area
     * @param startY     vertical start of the list area
     * @param noItemsKey translation key for the "no items" message (line 1)
     * @param hintKey    translation key for the hint message (line 2, italic)
     */
    public static void renderEmptyState(
        GuiGraphics graphics,
        Font font,
        int centerX,
        int startY,
        String noItemsKey,
        String hintKey
    ) {
        graphics.drawCenteredString(
            font,
            Component.translatable(noItemsKey).withStyle(ChatFormatting.GRAY),
            centerX,
            startY + 20,
            GuiColors.TEXT_DISABLED
        );
        graphics.drawCenteredString(
            font,
            Component.translatable(hintKey).withStyle(ChatFormatting.ITALIC),
            centerX,
            startY + 35,
            GuiColors.TEXT_DISABLED
        );
    }

    /**
     * Renders a {@code [count/max]} badge right-aligned at the given position.
     * Uses {@link GuiColors#WARNING} color when count reaches max capacity.
     *
     * @param graphics the graphics context
     * @param font     the font renderer
     * @param count    current prisoner count
     * @param max      maximum prisoner capacity
     * @param rightX   right edge X coordinate (badge is right-aligned to this minus 8px)
     * @param y        Y coordinate for the text
     */
    public static void renderCountBadge(
        GuiGraphics graphics,
        Font font,
        int count,
        int max,
        int rightX,
        int y
    ) {
        String countStr = "[" + count + "/" + max + "]";
        int color = count >= max ? GuiColors.WARNING : GuiColors.TEXT_GRAY;
        graphics.drawString(
            font,
            countStr,
            rightX - font.width(countStr) - 8,
            y,
            color
        );
    }
}
