import { EquipmentSlot, world } from "@minecraft/server";
import { runInterval } from "../utils";

/**
 * Class representing an item description.
 */
class ItemDescription {
  /**
   * Create an item description.
   * @param {string} id - The ID of the item.
   * @param {string[]} lore - The lore of the item.
   */
  constructor(id, lore) {
    this.id = id;
    this.lore = lore;
  }
}

/**
 * Array of item descriptions.
 * @type {ItemDescription[]}
 */
const itemDescriptions = [
  new ItemDescription("ecbl_bc:antler_helmet", ["§r§5Grants Knockback effect."]),
  new ItemDescription("ecbl_bc:bear_claw", ["§r§5Grants Bleeding effect on-hit."]),
  new ItemDescription("ecbl_bc:fur_boots", ["§r§5Grants Speed II in cold biomes."]),
];

runInterval(async () => {
  for (const player of world.players) {
    for (const iDes of itemDescriptions) {
      const items = player.getItems(iDes.id);

      for (const [k, v] of items.equipments) {
        const item = v;

        if (item.getLore().length === 0) {
          item.setLore(iDes.lore);

          player.setEquipment(k, item);
        }
      }

      for (const [k, v] of items.inventory) {
        const item = v;

        if (item.getLore().length === 0) {
          item.setLore(iDes.lore);

          player.inventory.setItem(k, item);
        }
      }
    }
  }
});
