const backpacksMaterials = new Map([
  ["iron_backpack", "iron"],
  ["gold_backpack", "gold"],
  ["diamond_backpack", "diamond"],
]);
let previousBackpack = "sophisticatedbackpacks:backpack";

ServerEvents.recipes((event) => {
  backpacksMaterials.forEach((material, backpackType) => {
    const backpack = "sophisticatedbackpacks:" + backpackType;

    event.remove({ id: backpack });

    event.custom({
      type: "sophisticatedbackpacks:backpack_upgrade",
      key: {
        I: {
          tag:
            material != "diamond"
              ? `forge:ingots/${material}`
              : `forge:gems/${material}`,
        },
        C: {
          tag: `forge:storage_blocks/${material}`,
        },
        B: {
          item: previousBackpack,
        },
      },
      pattern: ["ICI", "IBI", "ICI"],
      result: {
        item: backpack,
      },
    });

    previousBackpack = backpack;
  });
});
