package fr.koka99cab.spiderman.registry;

import fr.koka99cab.spiderman.SpidermanMod;
import fr.koka99cab.spiderman.item.GrapplingRodItem;
import net.fabricmc.fabric.api.creativetab.v1.CreativeModeTabEvents;
import net.minecraft.core.Registry;
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.item.CreativeModeTab;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.Items;

public final class SpidermanItems {
	private static final ResourceKey<Item> GRAPPLING_HAND_KEY = key("grappling_hand");
	private static final ResourceKey<Item> GRAPPLING_ROD_KEY = key("grappling_rod");
	private static final ResourceKey<CreativeModeTab> INGREDIENTS_TAB = vanillaTab("ingredients");
	private static final ResourceKey<CreativeModeTab> TOOLS_TAB = vanillaTab("tools_and_utilities");

	public static final Item GRAPPLING_HAND = Registry.register(
			BuiltInRegistries.ITEM,
			GRAPPLING_HAND_KEY,
			new Item(new Item.Properties().setId(GRAPPLING_HAND_KEY))
	);

	public static final Item GRAPPLING_ROD = Registry.register(
			BuiltInRegistries.ITEM,
			GRAPPLING_ROD_KEY,
			new GrapplingRodItem(new Item.Properties().durability(64).setId(GRAPPLING_ROD_KEY))
	);

	private SpidermanItems() {
	}

	public static void register() {
		CreativeModeTabEvents.modifyOutputEvent(INGREDIENTS_TAB).register(entries -> entries.insertAfter(Items.TRIPWIRE_HOOK, GRAPPLING_HAND));
		CreativeModeTabEvents.modifyOutputEvent(TOOLS_TAB).register(entries -> entries.insertAfter(Items.FISHING_ROD, GRAPPLING_ROD));
		SpidermanMod.LOGGER.debug("Objets Spiderman enregistres.");
	}

	private static ResourceKey<Item> key(String path) {
		return ResourceKey.create(Registries.ITEM, SpidermanMod.id(path));
	}

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