package fr.koka99cab.ibelievechickenfly.registry;

import fr.koka99cab.ibelievechickenfly.IBelieveChickenFlyMod;
import fr.koka99cab.ibelievechickenfly.chickenfly.GoldenEggItem;
import fr.koka99cab.ibelievechickenfly.chickenfly.ModChickenVariants;
import net.fabricmc.fabric.api.creativetab.v1.CreativeModeTabEvents;
import net.minecraft.core.Registry;
import net.minecraft.core.component.DataComponents;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.core.registries.Registries;
import net.minecraft.resources.Identifier;
import net.minecraft.resources.ResourceKey;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.item.CreativeModeTab;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.Items;
import net.minecraft.world.item.Rarity;
import net.minecraft.world.item.SpawnEggItem;

public final class ModItems {
	private static final ResourceKey<Item> GOLDEN_EGG_KEY = ResourceKey.create(Registries.ITEM, IBelieveChickenFlyMod.id("golden_egg"));
	private static final ResourceKey<Item> BLUE_CHICKEN_SPAWN_EGG_KEY = ResourceKey.create(Registries.ITEM, IBelieveChickenFlyMod.id("blue_chicken_spawn_egg"));
	private static final ResourceKey<CreativeModeTab> INGREDIENTS_TAB = vanillaTab("ingredients");
	private static final ResourceKey<CreativeModeTab> SPAWN_EGGS_TAB = vanillaTab("spawn_eggs");

	public static final Item GOLDEN_EGG = Registry.register(
		BuiltInRegistries.ITEM,
		GOLDEN_EGG_KEY,
		new GoldenEggItem(new Item.Properties().stacksTo(16).rarity(Rarity.RARE).setId(GOLDEN_EGG_KEY))
	);

	public static final Item BLUE_CHICKEN_SPAWN_EGG = Registry.register(
		BuiltInRegistries.ITEM,
		BLUE_CHICKEN_SPAWN_EGG_KEY,
		new SpawnEggItem(new Item.Properties()
			.spawnEgg(EntityType.CHICKEN)
			.delayedHolderComponent(DataComponents.CHICKEN_VARIANT, ModChickenVariants.BLUE)
			.setId(BLUE_CHICKEN_SPAWN_EGG_KEY))
	);

	private ModItems() {
	}

	public static void register() {
		CreativeModeTabEvents.modifyOutputEvent(INGREDIENTS_TAB).register(entries -> entries.insertAfter(Items.EGG, GOLDEN_EGG));
		CreativeModeTabEvents.modifyOutputEvent(SPAWN_EGGS_TAB).register(entries -> entries.insertAfter(Items.CHICKEN_SPAWN_EGG, BLUE_CHICKEN_SPAWN_EGG));
		IBelieveChickenFlyMod.LOGGER.debug("Objets IBelieveChickenFly enregistres.");
	}

	private static ResourceKey<CreativeModeTab> vanillaTab(String path) {
		return ResourceKey.create(Registries.CREATIVE_MODE_TAB, Identifier.withDefaultNamespace(path));
	}
}
