package zone.oat.gmodtitlescreen;

import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.font.TextRenderer;
import net.minecraft.client.gui.screen.narration.NarrationMessageBuilder;
import net.minecraft.client.gui.screen.narration.NarrationPart;
import net.minecraft.client.gui.widget.ButtonWidget;
import net.minecraft.client.gui.widget.PressableTextWidget;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.text.Text;

@Environment(EnvType.CLIENT)
public class PressableTextWithTooltipWidget extends PressableTextWidget {
  protected final ButtonWidget.TooltipSupplier tooltipSupplier;

  public PressableTextWithTooltipWidget(int x, int y, int width, int height, Text text, ButtonWidget.PressAction onPress, TextRenderer textRenderer, ButtonWidget.TooltipSupplier tooltipSupplier) {
    super(x, y, width, height, text, onPress, textRenderer);
    this.tooltipSupplier = tooltipSupplier;
  }

  @Override
  public void renderTooltip(MatrixStack matrices, int mouseX, int mouseY) {
    super.renderTooltip(matrices, mouseX, mouseY);
    this.tooltipSupplier.onTooltip(this, matrices, mouseX, mouseY);
  }

  @Override
  public void appendNarrations(NarrationMessageBuilder builder) {
    super.appendNarrations(builder);
    this.appendDefaultNarrations(builder);
    this.tooltipSupplier.supply(text -> builder.put(NarrationPart.HINT, text));
  }
}
