package ru.dbotthepony.mc.otm.mixin;

import net.minecraft.client.User;
import net.minecraft.client.resources.SplashManager;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.server.packs.resources.ResourceManager;
import net.minecraft.util.profiling.ProfilerFiller;
import net.neoforged.fml.ModList;
import org.jetbrains.annotations.Nullable;
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;

import java.util.List;
import java.util.Locale;

@Mixin(SplashManager.class)
public abstract class SplashManagerMixin {
	@Shadow(remap = false)
	private List<String> splashes;
	@Shadow(remap = false)
	@Nullable
	private User user;

	@Inject(
		at = @At("TAIL"),
		remap = false,
		method = "apply(Ljava/util/List;Lnet/minecraft/server/packs/resources/ResourceManager;Lnet/minecraft/util/profiling/ProfilerFiller;)V"
	)
	public void otmSplashes(List<String> splashes, ResourceManager p_118879_, ProfilerFiller p_118880_, CallbackInfo ci) {
		this.splashes.add("42 is the answer!");
		this.splashes.add("Now with matter!");
		this.splashes.add("Now with four dimensions!");
		this.splashes.add("Now with more ways to slice Creepers!");
		this.splashes.add("Batteries not included!");
		this.splashes.add("As it was 13 nanoseconds ago!");
		this.splashes.add("Smart AI is smart enough to fail Turing test!");
		this.splashes.add("Neural computing!");
		this.splashes.add("Swimming through quantum fields!");
		this.splashes.add("For biological and digital alike!");
		this.splashes.add("Digital is the next form of Biological!");

		this.splashes.add("Also try Dota 2!");
		this.splashes.add("Also try Starbound!");
		this.splashes.add("Also try No Man's Sky!");
		this.splashes.add("Also try Factorio!");

		if (ModList.get().isLoaded("jei")) {
			this.splashes.add("E in JEI stands for Extraterrestrial!");
		}

		this.splashes.add("Smarter than Smart Cities!");

		if (BuiltInRegistries.ITEM.keySet().stream().noneMatch((it) -> it.getPath().contains("tin_")))
			this.splashes.add("Induction stove compatible!");

		if (BuiltInRegistries.ITEM.keySet().stream().noneMatch((it) -> it.getPath().contains("lead_")))
			this.splashes.add("Lead free!");

		if (BuiltInRegistries.ITEM.keySet().stream().noneMatch((it) -> it.getPath().contains("electrum_")))
			this.splashes.add("Somehow does not come with electrum!");

		if (BuiltInRegistries.ITEM.keySet().stream().noneMatch((it) -> it.getPath().contains("silver_")))
			this.splashes.add("Non-complementary to gold!");

		if (this.user != null) {
			var username = this.user.getName();

			this.splashes.add("Say no more, " + username + "!");
			this.splashes.add(username + ", and here comes the quarks!");

			if (ModList.get().isLoaded("ad_astra")) {
				this.splashes.add("Such a weird choice for Space Faring mod, " + username + "...");
			}
		}
	}
}
