package com.tiedup.remake.items;

import com.tiedup.remake.blocks.ModBlocks;
import com.tiedup.remake.core.TiedUpMod;
import com.tiedup.remake.items.base.*;
import com.tiedup.remake.v2.V2Items;
import com.tiedup.remake.v2.bondage.datadriven.DataDrivenBondageItem;
import com.tiedup.remake.v2.bondage.datadriven.DataDrivenItemDefinition;
import com.tiedup.remake.v2.bondage.datadriven.DataDrivenItemRegistry;
import net.minecraft.core.registries.Registries;
import net.minecraft.network.chat.Component;
import net.minecraft.world.item.CreativeModeTab;
import net.minecraft.world.item.ItemStack;
import net.minecraftforge.registries.DeferredRegister;
import net.minecraftforge.registries.RegistryObject;

/**
 * Creative Mode Tabs Registration
 * Defines the creative inventory tabs where TiedUp items will appear.
 *
 * All bondage items are now sourced from DataDrivenItemRegistry.
 */
@SuppressWarnings("null") // Minecraft API guarantees non-null returns
public class ModCreativeTabs {

    public static final DeferredRegister<CreativeModeTab> CREATIVE_MODE_TABS =
        DeferredRegister.create(Registries.CREATIVE_MODE_TAB, TiedUpMod.MOD_ID);

    public static final RegistryObject<CreativeModeTab> TIEDUP_TAB =
        CREATIVE_MODE_TABS.register("tiedup_tab", () ->
            CreativeModeTab.builder()
                .title(Component.translatable("itemGroup.tiedup"))
                .icon(() -> {
                    // Use first data-driven item as icon, or fallback to whip
                    var allDefs = DataDrivenItemRegistry.getAll();
                    if (!allDefs.isEmpty()) {
                        return DataDrivenBondageItem.createStack(allDefs.iterator().next().id());
                    }
                    return new ItemStack(ModItems.WHIP.get());
                })
                .displayItems((parameters, output) -> {
                    // ========== DATA-DRIVEN BONDAGE ITEMS ==========
                    // All binds, gags, blindfolds, earplugs, mittens, collars,
                    // hood, medical gag, etc. are now data-driven
                    for (DataDrivenItemDefinition def : DataDrivenItemRegistry.getAll()) {
                        output.accept(
                            DataDrivenBondageItem.createStack(def.id())
                        );
                    }

                    // ========== CLOTHES ==========
                    output.accept(ModItems.CLOTHES.get());

                    // ========== KNIVES (from enum) ==========
                    for (KnifeVariant variant : KnifeVariant.values()) {
                        output.accept(ModItems.getKnife(variant));
                    }

                    // ========== OTHER TOOLS ==========
                    output.accept(ModItems.WHIP.get());
                    output.accept(ModItems.PADDLE.get());
                    output.accept(ModItems.SHOCKER_CONTROLLER.get());
                    output.accept(ModItems.GPS_LOCATOR.get());
                    output.accept(ModItems.COLLAR_KEY.get());
                    output.accept(ModItems.LOCKPICK.get());
                    output.accept(ModItems.COMMAND_WAND.get());

                    // ========== SPECIAL ITEMS ==========
                    output.accept(ModItems.CHLOROFORM_BOTTLE.get());
                    output.accept(ModItems.RAG.get());
                    output.accept(ModItems.PADLOCK.get());
                    output.accept(ModItems.MASTER_KEY.get());
                    output.accept(ModItems.ROPE_ARROW.get());
                    output.accept(ModItems.TOKEN.get());

                    // ========== SPAWN EGGS ==========
                    output.accept(ModItems.DAMSEL_SPAWN_EGG.get());

                    // ========== GUIDE BOOK ==========
                    output.accept(ModItems.TIEDUP_GUIDE.get());

                    // ========== BLOCKS ==========
                    output.accept(ModBlocks.PADDED_BLOCK.get());
                    output.accept(ModBlocks.PADDED_SLAB.get());
                    output.accept(ModBlocks.PADDED_STAIRS.get());
                    output.accept(ModBlocks.ROPE_TRAP.get());
                    output.accept(ModBlocks.KIDNAP_BOMB.get());
                    output.accept(ModBlocks.TRAPPED_CHEST.get());
                    output.accept(ModBlocks.CELL_DOOR.get());
                    output.accept(ModBlocks.CELL_CORE.get());

                    // ========== V2 PET FURNITURE ==========
                    output.accept(V2Items.PET_BOWL.get());
                    output.accept(V2Items.PET_BED.get());
                    output.accept(V2Items.PET_CAGE.get());

                    // ========== V2 BONDAGE ITEMS ==========
                    output.accept(
                        com.tiedup.remake.v2.bondage.V2BondageItems.V2_HANDCUFFS.get()
                    );

                    // ========== FURNITURE PLACER ITEMS ==========
                    for (com.tiedup.remake.v2.furniture.FurnitureDefinition def : com.tiedup.remake.v2.furniture.FurnitureRegistry.getAll()) {
                        output.accept(
                            com.tiedup.remake.v2.furniture.FurniturePlacerItem.createStack(
                                def.id()
                            )
                        );
                    }
                })
                .build()
        );
}
