import { world, MolangVariableMap, EquipmentSlot } from "@minecraft/server";
/* 
Checks which item is in the mainhand
Adds effect if a specific item like a sword/spear is in the mainhand
*/

export function itemHold(player) {
  const typeId = player.typeId;
  if (typeId !== "minecraft:player") return;
  const mainhandEquipment = player.getComponent("equippable").getEquipment("Mainhand");
  const offhandEquipment = player.getComponent("equippable").getEquipment("Offhand");

  // if (mainhandEquipment == undefined) return;
  // // // //////////world.sendMessage(mainhandEquipment.typeId);
  // // // //////////world.sendMessage(offhandEquipment.typeId);

  let animationKey = "";

  // Check combination of equipment
  // // //////////world.sendMessage("switch");
  switch (true) {
    case mainhandEquipment?.typeId === "hb_cb:diamond_poppy_item" && offhandEquipment?.typeId === "hb_cb:diamond_poppy_item":
      animationKey = "animation.hb_cb.diamond_poppy_item.player_hold_both";
      // //////////world.sendMessage("animation.hb_cb.diamond_poppy_item.player_hold_both");
      break;
    case mainhandEquipment?.typeId === "hb_cb:ancient_lantern_item" && offhandEquipment?.typeId === "hb_cb:ancient_lantern_item":
      animationKey = "animation.hb_cb.ancient_lantern.player_hold_both";
      // //////////world.sendMessage("animation.hb_cb.ancient_lantern.player_hold_both");
      break;
    case mainhandEquipment?.typeId === "hb_cb:bell_staff_item" && offhandEquipment?.typeId === "hb_cb:bell_staff_item":
      animationKey = "animation.hb_cb.bell_staff.player_hold_both";
      // //////////world.sendMessage("animation.hb_cb.bell_staff.player_hold_both");
      break;
    case mainhandEquipment?.typeId === "hb_cb:ancient_lantern_item" && offhandEquipment?.typeId === "hb_cb:bell_staff_item":
      animationKey = "animation.hb_cb.ancient_lantern.player_hold_mainhand_bell_staff.player_hold_offhand";
      // //////////world.sendMessage("animation.hb_cb.ancient_lantern.player_hold_mainhand_bell_staff.player_hold_offhand");
      break;
    case mainhandEquipment?.typeId === "hb_cb:ancient_lantern_item" && offhandEquipment?.typeId === "hb_cb:diamond_poppy_item":
      animationKey = "animation.hb_cb.ancient_lantern.player_hold_mainhand_diamond_poppy.player_hold_offhand";
      // //////////world.sendMessage("animation.hb_cb.ancient_lantern.player_hold_mainhand_diamond_poppy.player_hold_offhand");
      break;
    case mainhandEquipment?.typeId === "hb_cb:bell_staff_item" && offhandEquipment?.typeId === "hb_cb:ancient_lantern_item":
      animationKey = "animation.hb_cb.bell_staff.player_hold_mainhand_ancient_lantern.player_hold_offhand";
      // //////////world.sendMessage("animation.hb_cb.bell_staff.player_hold_mainhand_ancient_lantern.player_hold_offhand");
      break;
    case mainhandEquipment?.typeId === "hb_cb:bell_staff_item" && offhandEquipment?.typeId === "hb_cb:diamond_poppy_item":
      animationKey = "animation.hb_cb.bell_staff.player_hold_mainhand_diamond_poppy.player_hold_offhand";
      // //////////world.sendMessage("animation.hb_cb.bell_staff.player_hold_mainhand_diamond_poppy.player_hold_offhand");
      break;
    case mainhandEquipment?.typeId === "hb_cb:diamond_poppy_item" && offhandEquipment?.typeId === "hb_cb:ancient_lantern_item":
      animationKey = "animation.hb_cb.diamond_poppy.player_hold_mainhand_ancient_lantern.player_hold_offhand";
      // //////////world.sendMessage("animation.hb_cb.diamond_poppy.player_hold_mainhand_ancient_lantern.player_hold_offhand");
      break;
    case mainhandEquipment?.typeId === "hb_cb:diamond_poppy_item" && offhandEquipment?.typeId === "hb_cb:bell_staff_item":
      animationKey = "animation.hb_cb.diamond_poppy.player_hold_mainhand_bell_staff.player_hold_offhand";
      // //////////world.sendMessage("animation.hb_cb.diamond_poppy.player_hold_mainhand_bell_staff.player_hold_offhand");
      break;

    // Case for when both hands are empty
    case mainhandEquipment === undefined && offhandEquipment === undefined:
      // // //////////world.sendMessage("both hands empty");
      return;

    // Case when one hand is empty
    case mainhandEquipment?.typeId === "hb_cb:ancient_lantern_item" && offhandEquipment === undefined:
      // // //////////world.sendMessage("empty offhand");
      animationKey = "animation.hb_cb.ancient_lantern.player_hold_mainhand_empty_offhand";
      // //////////world.sendMessage("animation.hb_cb.ancient_lantern.player_hold_mainhand_empty_offhand");
      break;
    case mainhandEquipment?.typeId === "hb_cb:bell_staff_item" && offhandEquipment === undefined:
      // // //////////world.sendMessage("empty offhand");
      animationKey = "animation.hb_cb.bell_staff.player_hold_mainhand_empty_offhand";
      // //////////world.sendMessage("animation.hb_cb.bell_staff.player_hold_mainhand_empty_offhand");
      break;
    case mainhandEquipment?.typeId === "hb_cb:diamond_poppy_item" && offhandEquipment === undefined:
      // // //////////world.sendMessage("empty offhand");
      animationKey = "animation.hb_cb.diamond_poppy.player_hold_mainhand_empty_offhand";
      // //////////world.sendMessage("animation.hb_cb.diamond_poppy.player_hold_mainhand_empty_offhand");
      break;
    case mainhandEquipment === undefined && offhandEquipment?.typeId === "hb_cb:ancient_lantern_item":
      // // //////////world.sendMessage("empty mainhand");
      animationKey = "animation.hb_cb.ancient_lantern.player_hold_offhand_empty_mainhand";
      // //////////world.sendMessage("animation.hb_cb.ancient_lantern.player_hold_offhand_empty_mainhand");
      break;
    case mainhandEquipment === undefined && offhandEquipment?.typeId === "hb_cb:bell_staff_item":
      // // //////////world.sendMessage("empty mainhand");
      animationKey = "animation.hb_cb.bell_staff.player_hold_offhand_empty_mainhand";
      // //////////world.sendMessage("animation.hb_cb.bell_staff.player_hold_offhand_empty_mainhand");
      break;
    case mainhandEquipment === undefined && offhandEquipment?.typeId === "hb_cb:diamond_poppy_item":
      // // //////////world.sendMessage("empty mainhand");
      animationKey = "animation.hb_cb.diamond_poppy.player_hold_offhand_empty_mainhand";
      // //////////world.sendMessage("animation.hb_cb.diamond_poppy.player_hold_offhand_empty_mainhand");
      break;

    // Case when one hand is defined but the other is not
    case mainhandEquipment?.typeId === "hb_cb:ancient_lantern_item" && offhandEquipment !== undefined:
      // // //////////world.sendMessage("empty offhand");
      animationKey = "animation.hb_cb.ancient_lantern.player_hold_mainhand_empty_offhand";
      // //////////world.sendMessage("animation.hb_cb.ancient_lantern.player_hold_mainhand_empty_offhand");
      break;
    case mainhandEquipment?.typeId === "hb_cb:bell_staff_item" && offhandEquipment !== undefined:
      // // //////////world.sendMessage("empty offhand");
      animationKey = "animation.hb_cb.bell_staff.player_hold_mainhand_empty_offhand";
      // //////////world.sendMessage("animation.hb_cb.bell_staff.player_hold_mainhand_empty_offhand");
      break;
    case mainhandEquipment?.typeId === "hb_cb:diamond_poppy_item" && offhandEquipment !== undefined:
      // // //////////world.sendMessage("empty offhand");
      animationKey = "animation.hb_cb.diamond_poppy.player_hold_mainhand_empty_offhand";
      // //////////world.sendMessage("animation.hb_cb.diamond_poppy.player_hold_mainhand_empty_offhand");
      break;
    case mainhandEquipment !== undefined && offhandEquipment?.typeId === "hb_cb:ancient_lantern_item":
      // // //////////world.sendMessage("empty mainhand");
      animationKey = "animation.hb_cb.ancient_lantern.player_hold_offhand_empty_mainhand";
      // //////////world.sendMessage("animation.hb_cb.ancient_lantern.player_hold_offhand_empty_mainhand");
      break;
    case mainhandEquipment !== undefined && offhandEquipment?.typeId === "hb_cb:bell_staff_item":
      // // //////////world.sendMessage("empty mainhand");
      animationKey = "animation.hb_cb.bell_staff.player_hold_offhand_empty_mainhand";
      // //////////world.sendMessage("animation.hb_cb.bell_staff.player_hold_offhand_empty_mainhand");
      break;
    case mainhandEquipment !== undefined && offhandEquipment?.typeId === "hb_cb:diamond_poppy_item":
      // // //////////world.sendMessage("empty mainhand");
      animationKey = "animation.hb_cb.diamond_poppy.player_hold_offhand_empty_mainhand";
      // //////////world.sendMessage("animation.hb_cb.diamond_poppy.player_hold_offhand_empty_mainhand");
  }

  if (animationKey) {
    // // //////////world.sendMessage(animationKey);
    // Trigger animation (for example, using a method like player.playAnimation())
    player.playAnimation(animationKey);
  }
}
