package com.r3944realms.modernlifepatch.mixin.item;

import com.dairymoose.modernlife.items.CameraItem;
import com.dairymoose.modernlife.util.CanvasData;
import com.mojang.blaze3d.platform.NativeImage;
import com.r3944realms.modernlifepatch.ModernLifePatch;
import com.r3944realms.modernlifepatch.datagen.lang.ModLangKeyValue;
import net.minecraft.nbt.ListTag;
import net.minecraft.nbt.Tag;
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.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

import java.util.List;

@Mixin(CameraItem.class)
public abstract class MixinCamera {
    @Inject(method = {"appendHoverText"}, at= @At("HEAD"), cancellable = true)
    public void appendHoverText(ItemStack itemStack, Level world, List<Component> text, TooltipFlag flag, CallbackInfo ci) {
        int photoCount = 0;
        if (itemStack.getTag() != null && itemStack.getTag().contains("ImageList")) {
            Tag imageListTag = itemStack.getTag().get("ImageList");
            ListTag imageList;
            if (imageListTag instanceof ListTag) {
                imageList = (ListTag)imageListTag;
                photoCount = imageList.size();
            }
        }

        int maxPhotos = itemStack.getMaxDamage();
        text.add(Component.translatable(ModLangKeyValue.CAMERA_HOVER_FIRST.getKey(),photoCount, maxPhotos));
        text.add(Component.literal(""));
        text.add(Component.translatable(ModLangKeyValue.CAMERA_HOVER_SECOND.getKey()));
        text.add(Component.translatable(ModLangKeyValue.CAMERA_HOVER_THIRD.getKey()));
        ci.cancel();
    }

}
