package com.tiedup.remake.items;

import com.tiedup.remake.blocks.ModBlocks;
import com.tiedup.remake.core.TiedUpMod;
import com.tiedup.remake.entities.KidnapperItemSelector;
import com.tiedup.remake.items.base.*;
import com.tiedup.remake.v2.V2Items;
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.
 *
 * Updated to use factory pattern with enum-based item registration.
 */
@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(() -> new ItemStack(ModItems.getBind(BindVariant.ROPES)))
                .displayItems((parameters, output) -> {
                    // ========== BINDS (from enum) ==========
                    for (BindVariant variant : BindVariant.values()) {
                        // Add base item
                        output.accept(ModItems.getBind(variant));

                        // Add colored variants if supported
                        if (variant.supportsColor()) {
                            for (ItemColor color : ItemColor.values()) {
                                // Skip special colors (caution, clear) except for duct tape
                                if (
                                    color.isSpecial() &&
                                    variant != BindVariant.DUCT_TAPE
                                ) continue;
                                // Use validation method to check if color has texture
                                if (
                                    KidnapperItemSelector.isColorValidForBind(
                                        color,
                                        variant
                                    )
                                ) {
                                    output.accept(
                                        KidnapperItemSelector.createBind(
                                            variant,
                                            color
                                        )
                                    );
                                }
                            }
                        }
                    }

                    // ========== GAGS (from enum) ==========
                    for (GagVariant variant : GagVariant.values()) {
                        // Add base item
                        output.accept(ModItems.getGag(variant));

                        // Add colored variants if supported
                        if (variant.supportsColor()) {
                            for (ItemColor color : ItemColor.values()) {
                                // Skip special colors (caution, clear) except for tape gag
                                if (
                                    color.isSpecial() &&
                                    variant != GagVariant.TAPE_GAG
                                ) continue;
                                // Use validation method to check if color has texture
                                if (
                                    KidnapperItemSelector.isColorValidForGag(
                                        color,
                                        variant
                                    )
                                ) {
                                    output.accept(
                                        KidnapperItemSelector.createGag(
                                            variant,
                                            color
                                        )
                                    );
                                }
                            }
                        }
                    }

                    // ========== BLINDFOLDS (from enum) ==========
                    for (BlindfoldVariant variant : BlindfoldVariant.values()) {
                        // Add base item
                        output.accept(ModItems.getBlindfold(variant));

                        // Add colored variants if supported
                        if (variant.supportsColor()) {
                            for (ItemColor color : ItemColor.values()) {
                                // Skip special colors for blindfolds
                                if (color.isSpecial()) continue;
                                // Use validation method to check if color has texture
                                if (
                                    KidnapperItemSelector.isColorValidForBlindfold(
                                        color,
                                        variant
                                    )
                                ) {
                                    output.accept(
                                        KidnapperItemSelector.createBlindfold(
                                            variant,
                                            color
                                        )
                                    );
                                }
                            }
                        }
                    }

                    // Hood (combo item, not in enum)
                    output.accept(ModItems.HOOD.get());

                    // ========== 3D ITEMS ==========
                    output.accept(ModItems.BALL_GAG_3D.get());

                    // ========== COMBO ITEMS ==========
                    output.accept(ModItems.MEDICAL_GAG.get());

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

                    // ========== COLLARS ==========
                    output.accept(ModItems.CLASSIC_COLLAR.get());
                    output.accept(ModItems.CHOKE_COLLAR.get());
                    output.accept(ModItems.SHOCK_COLLAR.get());
                    output.accept(ModItems.GPS_COLLAR.get());

                    // ========== EARPLUGS (from enum) ==========
                    for (EarplugsVariant variant : EarplugsVariant.values()) {
                        output.accept(ModItems.getEarplugs(variant));
                    }

                    // ========== MITTENS (from enum) ==========
                    for (MittensVariant variant : MittensVariant.values()) {
                        output.accept(ModItems.getMittens(variant));
                    }

                    // ========== 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()
                    );

                    // ========== DATA-DRIVEN BONDAGE ITEMS ==========
                    for (com.tiedup.remake.v2.bondage.datadriven.DataDrivenItemDefinition def : com.tiedup.remake.v2.bondage.datadriven.DataDrivenItemRegistry.getAll()) {
                        output.accept(
                            com.tiedup.remake.v2.bondage.datadriven.DataDrivenBondageItem.createStack(
                                def.id()
                            )
                        );
                    }

                    // ========== 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()
        );
}
