package com.acethewildfire.acesbs.item;

import com.acethewildfire.acesbs.AcesBS;
import com.acethewildfire.acesbs.block.ModBlocks;
import com.acethewildfire.acesbs.entity.ModEntities;
import com.acethewildfire.acesbs.item.custom.*;
import com.acethewildfire.acesbs.potion.ModPotions;
import com.acethewildfire.acesbs.sounds.ModSounds;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.component.DataComponentTypes;
import net.minecraft.component.type.AttributeModifierSlot;
import net.minecraft.component.type.AttributeModifiersComponent;
import net.minecraft.component.type.LoreComponent;
import net.minecraft.component.type.PotionContentsComponent;
import net.minecraft.entity.attribute.EntityAttributeModifier;
import net.minecraft.entity.attribute.EntityAttributes;
import net.minecraft.item.*;
import net.minecraft.item.tooltip.TooltipType;
import net.minecraft.registry.Registries;
import net.minecraft.registry.Registry;
import net.minecraft.text.Text;
import net.minecraft.util.Formatting;
import net.minecraft.util.Identifier;

import java.util.List;

public class ModItems {
    public static final Item ORACLE_LEMON = registerItem("oracle_lemon", new OracleLemon(new Item.Settings().component(DataComponentTypes.POTION_CONTENTS, new PotionContentsComponent(ModPotions.LEMON))));
    public static final Item WAND = registerItem("wand", new Wand(new Item.Settings().maxDamage(32)));
    public static final Item RAW_ENTROPY = registerItem("raw_entropy", new Item(new Item.Settings()));
    public static final Item STABLE_ENTROPY = registerItem("stable_entropy", new Item(new Item.Settings()));
    public static final Item RAW_ENDTROPY = registerItem("raw_endtropy", new Item(new Item.Settings()));
    public static final Item STABLE_ENDTROPY = registerItem("stable_endtropy", new Item(new Item.Settings()));
    public static final Item INFERNAL_ASHES = registerItem("infernal_ashes", new Item(new Item.Settings()));
    public static final Item INFERNAL_BEEF = registerItem("infernal_beef",
            new Item(new Item.Settings()
                    .food(ModFoodComponent.INFERNAL_BEEF)
                    .fireproof()
                    .component(DataComponentTypes.LORE, new LoreComponent(
                            List.of(
                                    Text.literal("Brimstone fed").formatted(Formatting.DARK_RED, Formatting.ITALIC),
                                    Text.literal("Non-holy").formatted(Formatting.DARK_RED, Formatting.ITALIC)
                            )
                    ))
            ));
    public static final Item BRICKED_UP = registerItem("bricked_up",
            new Item(new Item.Settings()
                    .food(ModFoodComponent.BRICKED_UP)
                    .component(DataComponentTypes.LORE, new LoreComponent(
                            List.of(
                                    Text.literal("Straight to God").formatted(Formatting.GOLD, Formatting.ITALIC)
                            )
                    ))
            ));

    public static final Item COMBUSTIBLE_LEMON = registerItem("combustible_lemon",
            new CombustibleLemon(new Item.Settings().maxCount(16)){
                @Override
                public void appendTooltip(ItemStack stack, TooltipContext context, List<Text> tooltip, TooltipType type) {
                    tooltip.add(Text.translatable("tooltip.acesbs.combustible_lemon1"));
                    tooltip.add(Text.translatable("tooltip.acesbs.combustible_lemon2"));
                    super.appendTooltip(stack, context, tooltip, type);
                }
            });

    public static final Item LEMON = registerItem("lemon", new Item(new Item.Settings().food(ModFoodComponent.LEMON)));
    public static final Item COOKED_LEMON = registerItem("cooked_lemon", new Item(new Item.Settings().food(ModFoodComponent.COOKED_LEMON)));
    public static final Item GREEN_BRICKS = registerItem("green_bricks", new Item(new Item.Settings()) {
        @Override
        public void appendTooltip(ItemStack stack, TooltipContext context, List<Text> tooltip, TooltipType type) {
            if(!Screen.hasShiftDown()){
                tooltip.add(Text.translatable("tooltip.acesbs.generic.shift_up"));
            }
            else {
                tooltip.add(Text.translatable("tooltip.acesbs.green_bricks"));
            }
            super.appendTooltip(stack, context, tooltip, type);
        }
    });

    public static final Item MOTE_OF_ORDER = registerItem("mote_of_order", new Item(new Item.Settings()) {
        public void appendTooltip(ItemStack stack, TooltipContext context, List<Text> tooltip, TooltipType type) {
            if(!Screen.hasShiftDown()){
                tooltip.add(Text.translatable("tooltip.acesbs.generic.shift_up"));
            }
            else {
                tooltip.add(Text.translatable("tooltip.acesbs.mote_of_order"));
            }
            super.appendTooltip(stack, context, tooltip, type);
        }
    });

    public static final Item KAUPEN_BOW = registerItem("kaupen_bow",
            new BowItem(new Item.Settings().maxDamage(500)) {
                @Override
                public void appendTooltip(ItemStack stack, TooltipContext context, List<Text> tooltip, TooltipType type) {

                    if(!Screen.hasShiftDown()){
                        tooltip.add(Text.translatable("tooltip.acesbs.generic.shift_up"));
                    }
                    else {
                        tooltip.add(Text.translatable("tooltip.acesbs.kaupen_bow"));
                        tooltip.add(Text.translatable("tooltip.acesbs.kaupen_bow_2"));
                    }
                    super.appendTooltip(stack, context, tooltip, type);
                }
            });

    public static final Item CRAB_RAVE_MUSIC_DISC = registerItem("crab_rave_music_disc",
            new Item(new Item.Settings().jukeboxPlayable(ModSounds.CRAB_RAVE_KEY).maxCount(1)));

    public static final Item BERSERKERS_PAULDRON = registerItem("berserkers_pauldron",
            new ModArmorItem(ModArmorMaterials.BERSERKERS, ArmorItem.Type.CHESTPLATE, new Item.Settings()
                    .maxDamage(ArmorItem.Type.CHESTPLATE.getMaxDamage(15))
                    .attributeModifiers(AttributeModifiersComponent.builder()
                            .add(EntityAttributes.GENERIC_MAX_HEALTH,
                                    new EntityAttributeModifier(Identifier.of(AcesBS.MOD_ID, "generic.max_health"), 20, EntityAttributeModifier.Operation.ADD_VALUE), AttributeModifierSlot.CHEST)
                            .add(EntityAttributes.GENERIC_ARMOR,
                                    new EntityAttributeModifier(Identifier.of(AcesBS.MOD_ID, "generic.armor"), -20, EntityAttributeModifier.Operation.ADD_VALUE), AttributeModifierSlot.CHEST)
                            .add(EntityAttributes.GENERIC_KNOCKBACK_RESISTANCE,
                                    new EntityAttributeModifier(Identifier.of(AcesBS.MOD_ID, "generic.knockback_resistance"), 1.0f, EntityAttributeModifier.Operation.ADD_VALUE), AttributeModifierSlot.CHEST)
                            .build())){
                @Override
                public void appendTooltip(ItemStack stack, TooltipContext context, List<Text> tooltip, TooltipType type) {
                    if(!Screen.hasShiftDown()){
                        tooltip.add(Text.translatable("tooltip.acesbs.berserkers_pauldron_desc"));
                        tooltip.add(Text.translatable("tooltip.acesbs.generic.shift_more"));
                    }
                    else {
                        tooltip.add(Text.translatable("tooltip.acesbs.berserkers_pauldron_thanks"));
                        tooltip.add(Text.translatable("tooltip.acesbs.thanks_sov"));
                    }
                    super.appendTooltip(stack, context, tooltip, type);
                }
            }
    );

    public static final Item TOBACCO_SEEDS = registerItem("tobacco_seeds", new AliasedBlockItem(ModBlocks.TOBACCO_CROP, new Item.Settings()));

    public static final Item TOBACCO = registerItem("tobacco", new Item(new Item.Settings()));

    public static final Item CIGARETTE = registerItem("cigarette", new Cigarette(new Item.Settings().maxCount(20)));
    public static final Item CIGARETTE_LEMON = registerItem("cigarette_lemon", new CigaretteLemon(new Item.Settings().maxCount(20)));
    public static final Item CIGARETTE_FUNNY = registerItem("cigarette_funny", new CigaretteFunny(new Item.Settings().maxCount(20)){
        public void appendTooltip(ItemStack stack, TooltipContext context, List<Text> tooltip, TooltipType type) {
            if(!Screen.hasShiftDown()){
                tooltip.add(Text.translatable("tooltip.acesbs.generic.shift_up"));
            }
            else {
                tooltip.add(Text.translatable("tooltip.acesbs.cigarette_funny"));
            }
            super.appendTooltip(stack, context, tooltip, type);
        }
    });

    public static final Item FREN_SPAWN_EGG = registerItem("fren_spawn_egg",
            new SpawnEggItem(ModEntities.FREN, 894731, 0, new Item.Settings()));



    public static Item registerItem(String name, Item item){
        return Registry.register(Registries.ITEM, Identifier.of(AcesBS.MOD_ID, name), item);
    }

    public static void registerModItems() {
        PrismaSteelItems.registerPrismaItems();
        AcesBS.LOGGER.info("Registering Mod Items for " + AcesBS.MOD_ID);

//        ItemGroupEvents.modifyEntriesEvent(ItemGroups.INGREDIENTS).register(fabricItemGroupEntries -> {
//            fabricItemGroupEntries.add(ORACLE_LEMON);
//        });
    }
}
