import { world } from "@minecraft/server";
import { ActionFormData } from "@minecraft/server-ui";

const cajadosMago = [
  "well:cajado_mago",
  "well:cajado_mago2",
  "well:cajado_mago3",
  "well:cajado_mago4",
  "well:cajado_mago5"
];

const espadasHumano = [
  "well:espada_humano",
  "well:espada_humano2",
  "well:espada_humano3",
  "well:espada_humano4",
  "well:espada_humano5"
];

export function initCajadoMago() {
  world.afterEvents.itemUse.subscribe((eventData) => {
    const player = eventData.source;

    if (!player.isSneaking) return;

    if (cajadosMago.includes(eventData.itemStack.typeId)) {
      cajado_mago_skin(player);
    }
	
	
	if (espadasHumano.includes(eventData.itemStack.typeId)) {
      espadas_humano_skin(player);
    }
	
	
  });
}

function cajado_mago_skin(player) {
  const form = new ActionFormData()
    .title({ rawtext: [ { translate: "selecionar.skin.mago" }]}) //💠 Mudança de Skin
    .body("") // "Escolha a skin que deseja usar:"
    .button({ rawtext: [ { translate: "dialogue.mago.level.1" }]}, "textures/items/classes/cajado_mago.png")
    .button({ rawtext: [ { translate: "dialogue.mago.level.2" }]}, "textures/items/classes/cajado_mago2.png")
    .button({ rawtext: [ { translate: "dialogue.mago.level.3" }]}, "textures/items/classes/cajado_mago3.png")
    .button({ rawtext: [ { translate: "dialogue.mago.level.4" }]}, "textures/items/classes/cajado_mago4.png")
    .button({ rawtext: [ { translate: "dialogue.mago.level.5" }]}, "textures/items/classes/cajado_mago5.png");

  form.show(player).then((response) => {
    if (response.canceled) return;

    switch (response.selection) {
      case 0:
        //player.runCommand("say Você escolheu a Skin de Cura!");
		player.runCommand("event entity @s remove_animacao_combo");
		player.runCommand("scoreboard players set @s skill_ataque 0");
		player.runCommand("execute as @s [scores={skill_mago_orbe=0..}] run particle well:mudar_classe"),
		player.runCommand("replaceitem entity @s [scores={skill_mago_orbe=0..}] slot.hotbar 0 well:cajado_mago 1 0 {\"item_lock\": {\"mode\": \"lock_in_slot\"}, \"keep_on_death\": {}}");
		
		player.runCommand("titleraw @s [scores={skill_mago_orbe=0..}] actionbar {\"rawtext\":[ {\"translate\":\"dialogue.mago.level.1\"}]}");
		

        break;
      case 1:
        //player.runCommand("say Você escolheu a Skin de Gelo!");
		player.runCommand("event entity @s remove_animacao_combo");
		player.runCommand("scoreboard players set @s skill_ataque 0");
		player.runCommand("execute as @s [scores={skill_mago_orbe=5..}] run particle well:mudar_classe");
		player.runCommand("replaceitem entity @s [scores={skill_mago_orbe=5..}] slot.hotbar 0 well:cajado_mago2 1 0 {\"item_lock\": {\"mode\": \"lock_in_slot\"}, \"keep_on_death\": {}}");
		
		player.runCommand("titleraw @s [scores={skill_mago_orbe=5..}] actionbar {\"rawtext\":[ {\"translate\":\"dialogue.mago.level.2\"}]}");
		player.runCommand("titleraw @s [scores={skill_mago_orbe=..4}] title {\"rawtext\":[ {\"score\":{\"name\": \"@s\", \"objective\": \"skill_mago_orbe\"}}, {\"text\": \"/5\"}, {\"text\": \" \"}, {\"text\": \"\"}, {\"text\": \"\n\"}, {\"translate\":\"orbes.insuficientes\"}]}");
		
		player.runCommand("effect @s [scores={skill_mago_orbe=..4}] blindness 5 2 true");

        break;
      case 2:
        //player.runCommand("say Você escolheu a Skin de Choque!");
		player.runCommand("event entity @s remove_animacao_combo");
		player.runCommand("scoreboard players set @s skill_ataque 0");
		player.runCommand("execute as @s [scores={skill_mago_orbe=10..}] run particle well:mudar_classe");
		player.runCommand("replaceitem entity @s [scores={skill_mago_orbe=10..}] slot.hotbar 0 well:cajado_mago3 1 0 {\"item_lock\": {\"mode\": \"lock_in_slot\"}, \"keep_on_death\": {}}"); 
		
		player.runCommand("titleraw @s [scores={skill_mago_orbe=10..}] actionbar {\"rawtext\":[ {\"translate\":\"dialogue.mago.level.3\"}]}");
		player.runCommand("titleraw @s [scores={skill_mago_orbe=..9}] title {\"rawtext\":[ {\"score\":{\"name\": \"@s\", \"objective\": \"skill_mago_orbe\"}}, {\"text\": \"/10\"}, {\"text\": \" \"}, {\"text\": \"\"},  {\"text\": \"\n\"}, {\"translate\":\"orbes.insuficientes\"}]}");
		player.runCommand("effect @s [scores={skill_mago_orbe=..9}] blindness 5 2 true");
        break;
      case 3:
        //player.runCommand("say Você escolheu a Skin da Terra!");
		player.runCommand("event entity @s remove_animacao_combo");
		player.runCommand("scoreboard players set @s skill_ataque 0");
		player.runCommand("execute as @s [scores={skill_mago_orbe=20..}] run particle well:mudar_classe");
		player.runCommand("replaceitem entity @s [scores={skill_mago_orbe=20..}] slot.hotbar 0 well:cajado_mago4 1 0 {\"item_lock\": {\"mode\": \"lock_in_slot\"}, \"keep_on_death\": {}}"); 
		
		player.runCommand("titleraw @s [scores={skill_mago_orbe=20..}] actionbar {\"rawtext\":[ {\"translate\":\"dialogue.mago.level.4\"}]}");
		player.runCommand("titleraw @s [scores={skill_mago_orbe=..19}] title {\"rawtext\":[ {\"score\":{\"name\": \"@s\", \"objective\": \"skill_mago_orbe\"}}, {\"text\": \"/20\"}, {\"text\": \" \"}, {\"text\": \"\"},  {\"text\": \"\n\"}, {\"translate\":\"orbes.insuficientes\"}]}");
		player.runCommand("effect @s [scores={skill_mago_orbe=..19}] blindness 5 2 true");
        break;
      case 4:
        //player.runCommand("say Você escolheu a Skin de Fogo!");
		player.runCommand("event entity @s remove_animacao_combo");
		player.runCommand("scoreboard players set @s skill_ataque 0");
		player.runCommand("execute as @s [scores={skill_mago_orbe=30..}] run particle well:mudar_classe");
		player.runCommand("replaceitem entity @s [scores={skill_mago_orbe=30..}] slot.hotbar 0 well:cajado_mago5 1 0 {\"item_lock\": {\"mode\": \"lock_in_slot\"}, \"keep_on_death\": {}}"); 
		
		player.runCommand("titleraw @s [scores={skill_mago_orbe=30..}] actionbar {\"rawtext\":[ {\"translate\":\"dialogue.mago.level.5\"}]}");
		player.runCommand("titleraw @s [scores={skill_mago_orbe=..29}] title {\"rawtext\":[ {\"score\":{\"name\": \"@s\", \"objective\": \"skill_mago_orbe\"}}, {\"text\": \"/30\"}, {\"text\": \" \"}, {\"text\": \"\"},  {\"text\": \"\n\"}, {\"translate\":\"orbes.insuficientes\"}]}");
		player.runCommand("effect @s [scores={skill_mago_orbe=..29}] blindness 5 2 true");
        break;
    }
  });
}

function espadas_humano_skin(player) {
  const form = new ActionFormData()
	.title({ rawtext: [ { translate: "selecionar.skin.humano" }]})//💠 Mudança de Skin
    .body("") // "Escolha a skin que deseja usar:"
    .button({ rawtext: [ { translate: "dialogue.humano.level.1" }]}, "textures/items/classes/humano.png")
    .button({ rawtext: [ { translate: "dialogue.humano.level.2" }]}, "textures/items/classes/humano2.png")
    .button({ rawtext: [ { translate: "dialogue.humano.level.3" }]}, "textures/items/classes/humano3.png")
    .button({ rawtext: [ { translate: "dialogue.humano.level.4" }]}, "textures/items/classes/humano4.png")
    .button({ rawtext: [ { translate: "dialogue.humano.level.5" }]}, "textures/items/classes/humano5.png");
	
	//.title("💠 Mudança de Skin")
    //.body("Escolha a skin que deseja usar:")
    //.button({ rawtext: [ { translate: "Ladino" }]}, "textures/items/teleporterapido.png")
    //.button({ rawtext: [ { translate: "Caçador" }]}, "textures/items/teleporterapido.png")
    //.button({ rawtext: [ { translate: "Ninja" }]}, "textures/items/teleporterapido.png")
    //.button({ rawtext: [ { translate: "Machadão" }]}, "textures/items/teleporterapido.png")
    //.button({ rawtext: [ { translate: "Marretão" }]}, "textures/items/teleporterapido.png");
	

  form.show(player).then((response) => {
    if (response.canceled) return;

    switch (response.selection) {
      case 0:
        //player.runCommand("say Você escolheu a Skin de Cura!");
		player.runCommand("event entity @s remove_animacao_combo");
		player.runCommand("scoreboard players set @s skill_ataque 0");
		player.runCommand("execute as @s [scores={skill_humana_orbe=0..}] run particle well:mudar_classe"),
		player.runCommand("replaceitem entity @s [scores={skill_humana_orbe=0..}] slot.hotbar 0 well:espada_humano 1 0 {\"item_lock\": {\"mode\": \"lock_in_slot\"}, \"keep_on_death\": {}}");
		
		player.runCommand("titleraw @s [scores={skill_humana_orbe=0..}] actionbar {\"rawtext\":[ {\"translate\":\"dialogue.humana.level.1\"}]}");
		

        break;
      case 1:
        //player.runCommand("say Você escolheu a Skin de Gelo!");
		player.runCommand("event entity @s remove_animacao_combo");
		player.runCommand("scoreboard players set @s skill_ataque 0");
		player.runCommand("execute as @s [scores={skill_humana_orbe=5..}] run particle well:mudar_classe");
		player.runCommand("replaceitem entity @s [scores={skill_humana_orbe=5..}] slot.hotbar 0 well:espada_humano2 1 0 {\"item_lock\": {\"mode\": \"lock_in_slot\"}, \"keep_on_death\": {}}");
		
		player.runCommand("titleraw @s [scores={skill_humana_orbe=5..}] actionbar {\"rawtext\":[ {\"translate\":\"dialogue.humana.level.2\"}]}");
		player.runCommand("titleraw @s [scores={skill_humana_orbe=..4}] title {\"rawtext\":[ {\"score\":{\"name\": \"@s\", \"objective\": \"skill_humana_orbe\"}}, {\"text\": \"/5\"}, {\"text\": \" \"}, {\"text\": \"\"},  {\"text\": \"\n\"}, {\"translate\":\"orbes.insuficientes\"}]}");
		player.runCommand("effect @s [scores={skill_humana_orbe=..4}] blindness 5 2 true ");
        break;
      case 2:
        //player.runCommand("say Você escolheu a Skin de Choque!");
		player.runCommand("event entity @s remove_animacao_combo");
		player.runCommand("scoreboard players set @s skill_ataque 0");
		player.runCommand("execute as @s [scores={skill_humana_orbe=10..}] run particle well:mudar_classe");
		player.runCommand("replaceitem entity @s [scores={skill_humana_orbe=10..}] slot.hotbar 0 well:espada_humano3 1 0 {\"item_lock\": {\"mode\": \"lock_in_slot\"}, \"keep_on_death\": {}}"); 
		
		player.runCommand("titleraw @s [scores={skill_humana_orbe=10..}] actionbar {\"rawtext\":[ {\"translate\":\"dialogue.humana.level.3\"}]}");
		player.runCommand("titleraw @s [scores={skill_humana_orbe=..9}] title {\"rawtext\":[ {\"score\":{\"name\": \"@s\", \"objective\": \"skill_humana_orbe\"}}, {\"text\": \"/10\"}, {\"text\": \" \"}, {\"text\": \"\"},  {\"text\": \"\n\"}, {\"translate\":\"orbes.insuficientes\"}]}");
		player.runCommand("effect @s [scores={skill_humana_orbe=..9}] blindness 5 2 true ");
        break;
      case 3:
        //player.runCommand("say Você escolheu a Skin da Terra!");
		player.runCommand("event entity @s remove_animacao_combo");
		player.runCommand("scoreboard players set @s skill_ataque 0");
		player.runCommand("execute as @s [scores={skill_humana_orbe=20..}] run particle well:mudar_classe");
		player.runCommand("replaceitem entity @s [scores={skill_humana_orbe=20..}] slot.hotbar 0 well:espada_humano4 1 0 {\"item_lock\": {\"mode\": \"lock_in_slot\"}, \"keep_on_death\": {}}"); 
		
		player.runCommand("titleraw @s [scores={skill_humana_orbe=20..}] actionbar {\"rawtext\":[ {\"translate\":\"dialogue.humana.level.4\"}]}");
		player.runCommand("titleraw @s [scores={skill_humana_orbe=..19}] title {\"rawtext\":[ {\"score\":{\"name\": \"@s\", \"objective\": \"skill_humana_orbe\"}}, {\"text\": \"/20\"}, {\"text\": \" \"}, {\"text\": \"\"},  {\"text\": \"\n\"}, {\"translate\":\"orbes.insuficientes\"}]}");
		player.runCommand("effect @s [scores={skill_humana_orbe=..19}] blindness 5 2 true ");
        break;
      case 4:
        //player.runCommand("say Você escolheu a Skin de Fogo!");
		player.runCommand("event entity @s remove_animacao_combo");
		player.runCommand("scoreboard players set @s skill_ataque 0");
		player.runCommand("execute as @s [scores={skill_humana_orbe=30..}] run particle well:mudar_classe");
		player.runCommand("replaceitem entity @s [scores={skill_humana_orbe=30..}] slot.hotbar 0 well:espada_humano5 1 0 {\"item_lock\": {\"mode\": \"lock_in_slot\"}, \"keep_on_death\": {}}"); 
		
		player.runCommand("titleraw @s [scores={skill_humana_orbe=30..}] actionbar {\"rawtext\":[ {\"translate\":\"dialogue.humana.level.5\"}]}");
		player.runCommand("titleraw @s [scores={skill_humana_orbe=..29}] title {\"rawtext\":[ {\"score\":{\"name\": \"@s\", \"objective\": \"skill_humana_orbe\"}}, {\"text\": \"/30\"}, {\"text\": \" \"}, {\"text\": \"\"},  {\"text\": \"\n\"}, {\"translate\":\"orbes.insuficientes\"}]}");
		player.runCommand("effect @s [scores={skill_humana_orbe=..29}] blindness 5 2 true ");
        break;
    }
  });
}