// Revised itemlore.js
import { ItemStack } from "@minecraft/server";

// Define a mapping of item type IDs to their lore and tags
// const itemsToUpdate = {
//   "float_ad:tentacle_sword": {
//     lore: [`§l§6Tentacle Eruption`, `§r§eBackroom tentacles erupt from the ground`, `§8Use the sword to activate`],
//     tag: "tentacle_lore",
//   },
//   "float_ad:balloon_sword": {
//     lore: [`§l§6Balloon Launch`, `§r§eLevitate enemies into the sky`, `§8Use the sword to activate`],
//     tag: "balloon_lore",
//   },
//   "float_ad:stomper_sword": {
//     lore: [`§l§6Bone Tornado`, `§r§eUnleash a bone tornado`, `§8Use the sword to activate`],
//     tag: "stomper_lore",
//   },
//   "float_ad:skin_stealer_sword": {
//     lore: [`§l§6Tentacle Smash`, `§r§eBackroom tentacles knockback all enemies`, `§8Use the sword to activate`],
//     tag: "skin_stealer_lore",
//   },
//   "float_ad:dog_bowl": {
//     lore: [`§r§eHumphrey's finest kibble`, `§8Place Down in world.`],
//     tag: "dog_bowl_lore",
//   },
//   "float_ad:corruption_tool": {
//     lore: [`§r§eRemoves 'No-clip block portals' & 'Corruptors'`, `§8Interact with portal & corruptor to remove`],
//     tag: "corruption_tool_lore",
//   },
// };

let inventory,
  item,
  newItem,
  itemUpdate = undefined;

export default function updateAllItemLores(overworld) {
  overworld.getPlayers().forEach((player) => {
    inventory = player.getComponent(`minecraft:inventory`).container;
    for (let i = 0; i < inventory.size; i++) {
      item = inventory.getItem(i);
      if (item) {
        itemUpdate = itemsToUpdate[item.typeId];
        if (itemUpdate) {
          newItem = new ItemStack(item.typeId, item.amount);
          newItem.setLore(itemUpdate.lore);
          inventory.setItem(i, newItem);

          player.removeTag(itemUpdate.tag);
          if (itemUpdate.tag === "dog_bowl_lore") {
            player.runCommand("function fs/br/tags/dogbowl_removed");
          }
        }
      }
    }
  });
}
