package com.r3944realms.modernlifepatch.mixin.item;

import com.dairymoose.modernlife.items.FlashlightItem;
import com.r3944realms.modernlifepatch.datagen.lang.ModLangKeyValue;
import net.minecraft.network.chat.Component;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.TooltipFlag;
import net.minecraft.world.level.Level;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import java.util.List;

@Mixin(FlashlightItem.class)
public class MixinFlashLight {
    @Inject(method = {"appendHoverText"}, at= @At("HEAD"), cancellable = true)
    public void appendHoverText(ItemStack itemStack, Level world, List<Component> text, TooltipFlag flag, CallbackInfo ci) {
        String currentMinutes = String.valueOf((int)Math.floor((double)(itemStack.getMaxDamage() - itemStack.getDamageValue()) / 1200.0));
        String maxMinutes = String.valueOf(itemStack.getMaxDamage() / 1200);
        text.add(Component.translatable(ModLangKeyValue.FLASH_LIGHT_HOVER_FIFTH.getKey()));
        text.add(Component.translatable(ModLangKeyValue.FLASH_LIGHT_HOVER_SECOND.getKey()));
        text.add(Component.translatable(ModLangKeyValue.FLASH_LIGHT_HOVER_THIRD.getKey(), currentMinutes));
        text.add(Component.translatable(ModLangKeyValue.FLASH_LIGHT_HOVER_FOURTH.getKey(), maxMinutes));
        text.add(Component.translatable(ModLangKeyValue.FLASH_LIGHT_HOVER_FIFTH.getKey()));
        ci.cancel();
    }

}
