package net.darkhax.bookshelf.api.util;

import net.darkhax.bookshelf.mixin.entity.AccessorEntity;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.HoverEvent;
import net.minecraft.network.chat.MutableComponent;
import net.minecraft.network.chat.TextComponent;
import net.minecraft.network.chat.TranslatableComponent;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.StringUtil;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.item.ItemStack;

public final class TextHelper {

    public static MutableComponent getFormatedTime(int ticks, boolean includeHover) {

        MutableComponent component = new TextComponent(StringUtil.formatTickDuration(ticks));

        if (includeHover) {

            component = setHover(component, new TranslatableComponent("text.bookshelf.ticks", ticks));
        }

        return component;
    }

    public static <T extends Component> T setHover(T component, Component hoverInfo) {

        return setHover(component, HoverEvent.Action.SHOW_TEXT, hoverInfo);
    }

    public static <T extends Component> T setHover(T component, ItemStack hoverInfo) {

        return setHover(component, HoverEvent.Action.SHOW_ITEM, new HoverEvent.ItemStackInfo(hoverInfo));
    }

    public static <T extends Component> T setHover(T component, Entity hoverInfo) {

        if (hoverInfo instanceof AccessorEntity accessor) {

            return setHover(component, accessor.bookshelf$createHoverEvent());
        }

        return setHover(component, HoverEvent.Action.SHOW_ENTITY, new HoverEvent.EntityTooltipInfo(hoverInfo.getType(), hoverInfo.getUUID(), hoverInfo.getName()));
    }

    public static <T extends Component, AT, A extends HoverEvent.Action<AT>> T setHover(T component, A action, AT arg) {

        return setHover(component, new HoverEvent(action, arg));
    }

    public static <T extends Component, AT, A extends HoverEvent.Action<AT>> T setHover(T component, HoverEvent hoverInfo) {

        if (component instanceof MutableComponent mutable) {

            mutable.withStyle(style -> style.withHoverEvent(hoverInfo));
        }

        return component;
    }

    /**
     * Recursively applies a custom font to a text component and all of it's children components.
     *
     * @param text The text to apply the font to.
     * @param font The ID of the font to apply.
     * @return A modified text component that has had the font applied.
     */
    public static Component applyFont(Component text, ResourceLocation font) {

        if (text instanceof MutableComponent mutable) {

            mutable.withStyle(style -> style.withFont(font));
        }

        text.getSiblings().forEach(sib -> applyFont(sib, font));
        return text;
    }
}

@@ -67,35 +67,241 @@
 elf.
-mixin.entity.AccessorEntity
+api.Services;%0Aimport net.darkhax.bookshelf.mixin.client.AccessorFontManager;%0Aimport net.darkhax.bookshelf.mixin.client.AccessorMinecraft;%0Aimport net.darkhax.bookshelf.mixin.entity.AccessorEntity;%0Aimport net.minecraft.client.Minecraft
 ;%0Aim
@@ -724,39 +724,496 @@
 k;%0A%0A
-public final class TextHelper %7B
+import java.util.Collections;%0Aimport java.util.Set;%0A%0Apublic final class TextHelper %7B%0A%0A    public static final ResourceLocation FONT_ALT = new ResourceLocation(%22minecraft%22, %22alt%22);%0A    public static final ResourceLocation FONT_DEFAULT = new ResourceLocation(%22minecraft%22, %22default%22);%0A    public static final ResourceLocation FONT_ILLAGER = new ResourceLocation(%22minecraft%22, %22illageralt%22);%0A    public static final ResourceLocation FONT_UNIFORM = new ResourceLocation(%22minecraft%22, %22uniform%22);
 %0A%0A  
@@ -3438,11 +3438,335 @@
 t;%0A    %7D
+%0A%0A    public static Set%3CResourceLocation%3E getRegisteredFonts() %7B%0A%0A        if (!Services.PLATFORM.isPhysicalClient()) %7B%0A%0A            return Collections.emptySet();%0A        %7D%0A%0A        return ((AccessorFontManager) (((AccessorMinecraft) Minecraft.getInstance()).bookshelf$getFontManager())).bookshelf$getFonts().keySet();%0A    %7D
 %0A%7D%0A

Add a way to find all fonts registered on the client.