const artifacts = new Set([
  "myth:ring_of_swiftness",
  "myth:slimy_boots",
  "myth:shield_of_ashes",
  "myth:eye_of_sight",
  "myth:spell_book",
  "myth:amulet_of_attraction",
  "myth:forest_amulet",
  "myth:leam_hammer",
  "myth:silver_shovel",
  "myth:hourglass",
  "myth:skull",
  "myth:shield_of_shadow",
  "myth:worker_glove",
  "myth:magnetic_wand",
  "myth:arcane_rune",
  "myth:torch",
  "myth:jester_hat",
  "myth:magic_powder",
  "myth:experience_essence",
  "myth:life_essence",
]);

const weapons = new Set([
  "myth:astral_edge",
  "myth:celestial_sword",
  "myth:emperor_honor",
  "myth:enderstar_blade",
  "myth:excalibur",
  "myth:eye_of_ran",
  "myth:gungnir",
  "myth:hydra_bite",
  "myth:infernal_edge",
  "myth:jaguar_claw",
  "myth:kusanagi",
  "myth:laevateinn",
  "myth:masamune",
  "myth:mjolnir",
  "myth:muramasa",
  "myth:ocean_embrace",
  "myth:olympus_wrath",
  "myth:pharaoh_legacy",
  "myth:quetzalcoatl_fury",
  "myth:serpent_tongue",
  "myth:shadowreaper",
  "myth:soulfire_blade",
  "myth:spartan_valor",
  "myth:sphinx_judgment",
  "myth:trident_blade",
  "myth:voidrender",
  "myth:wavecutter",
]);

/**
 * @param {import("@minecraft/server").Player} player
 * @param {import("@minecraft/server").ItemStack} item
 * @param {number} index
 */
export async function itemLore(player, item, index) {
  if (item.getLore().length) {
    return;
  }
  const dir = artifacts.has(item.typeId) ? "artifacts" : weapons.has(item.typeId) ? "weapons" : null;
  if (dir) {
    const slot = index > 8 ? "slot.inventory" : "slot.hotbar";
    const slotIndex = index > 8 ? index - 9 : index;
    const identifier = item.typeId.split(":")[1];
    await player.runCommandAsync(`loot replace entity @s ${slot} ${slotIndex} loot "${dir}/${identifier}"`);
  }
}
