package com.acethewildfire.acesbs.item;

import com.acethewildfire.acesbs.AcesBS;
import com.acethewildfire.acesbs.block.ModBlocks;
import com.acethewildfire.acesbs.block.custom.CombustibleLemon;
import com.acethewildfire.acesbs.entity.ModEntities;
import com.acethewildfire.acesbs.item.custom.HammerItem;
import com.acethewildfire.acesbs.item.custom.ModArmorItem;
import com.acethewildfire.acesbs.item.custom.OracleLemon;
import com.acethewildfire.acesbs.item.custom.Wand;
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.*;
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.resource.featuretoggle.FeatureFlags;
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 PRISMA_STEEL = registerItem("prisma_steel", new Item(new Item.Settings()));
    public static final Item PRISMA_STEEL_SWORD = registerItem("prisma_steel_sword",
            new SwordItem(ModToolMaterials.PRISMA_STEEL, new Item.Settings()
                    .attributeModifiers(SwordItem.createAttributeModifiers(ModToolMaterials.PRISMA_STEEL, 3, -2.4f))));

    public static final Item PRISMA_STEEL_SHOVEL = registerItem("prisma_steel_shovel",
            new ShovelItem(ModToolMaterials.PRISMA_STEEL, new Item.Settings()
                    .attributeModifiers(ShovelItem.createAttributeModifiers(ModToolMaterials.PRISMA_STEEL, 1.5F, -3.0F)))
    );
    public static final Item PRISMA_STEEL_PICKAXE = registerItem("prisma_steel_pickaxe",
            new PickaxeItem(ModToolMaterials.PRISMA_STEEL, new Item.Settings()
                    .attributeModifiers(PickaxeItem.createAttributeModifiers(ModToolMaterials.PRISMA_STEEL, 1.0F, -2.8F)))
    );

    public static final Item PRISMA_STEEL_HAMMER = registerItem("prisma_steel_hammer",
            new HammerItem(ModToolMaterials.PRISMA_STEEL, new Item.Settings()
                    .attributeModifiers(PickaxeItem.createAttributeModifiers(ModToolMaterials.PRISMA_STEEL, 7.0F, -3.4F)))
    );

    public static final Item PRISMA_STEEL_AXE = registerItem("prisma_steel_axe",
            new AxeItem(ModToolMaterials.PRISMA_STEEL, new Item.Settings()
                    .attributeModifiers(AxeItem.createAttributeModifiers(ModToolMaterials.PRISMA_STEEL, 6.0F, -3.1F)))
    );
    public static final Item PRISMA_STEEL_HOE = registerItem("prisma_steel_hoe",
            new HoeItem(ModToolMaterials.PRISMA_STEEL, new Item.Settings()
                    .attributeModifiers(HoeItem.createAttributeModifiers(ModToolMaterials.PRISMA_STEEL, -2.0F, -1.0F)))
    );

    public static final Item PRISMA_STEEL_HELMET = registerItem("prisma_steel_helmet",
            new ModArmorItem(ModArmorMaterials.PRISMA_STEEL_ARMOR_MATERIAL, ArmorItem.Type.HELMET, new Item.Settings()
                    .maxDamage(ArmorItem.Type.HELMET.getMaxDamage(15))));

    public static final Item PRISMA_STEEL_CHESTPLATE = registerItem("prisma_steel_chestplate",
            new ModArmorItem(ModArmorMaterials.PRISMA_STEEL_ARMOR_MATERIAL, ArmorItem.Type.CHESTPLATE, new Item.Settings()
                    .maxDamage(ArmorItem.Type.CHESTPLATE.getMaxDamage(15))));

    public static final Item PRISMA_STEEL_LEGGINGS = registerItem("prisma_steel_leggings",
            new ModArmorItem(ModArmorMaterials.PRISMA_STEEL_ARMOR_MATERIAL, ArmorItem.Type.LEGGINGS, new Item.Settings()
                    .maxDamage(ArmorItem.Type.LEGGINGS.getMaxDamage(15))));

    public static final Item PRISMA_STEEL_BOOTS = registerItem("prisma_steel_boots",
            new ModArmorItem(ModArmorMaterials.PRISMA_STEEL_ARMOR_MATERIAL, ArmorItem.Type.BOOTS, new Item.Settings()
                    .maxDamage(ArmorItem.Type.BOOTS.getMaxDamage(15))));

    public static final Item PRISMA_SMITHING_TEMPLATE = registerItem("prisma_armor_trim_smithing_template",
            SmithingTemplateItem.of(Identifier.of(AcesBS.MOD_ID, "prisma"), FeatureFlags.VANILLA));

    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 FREN_SPAWN_EGG = registerItem("fren_spawn_egg",
            new SpawnEggItem(ModEntities.FREN, 894731, 0, new Item.Settings()));

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

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

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