const sweetish_fish_keys = [
    "candy_cane/sweetish_fish/sweetish_fish_red",
    "candy_cane/sweetish_fish/sweetish_fish_green",
    "candy_cane/sweetish_fish/sweetish_fish_yellow",
    "candy_cane/sweetish_fish/sweetish_fish_pink",
    "candy_cane/sweetish_fish/sweetish_fish_blue"
];

TetraJSEvents.workbenchCraft(event => {
    let { player, level, currentSchematic, currentSlot, targetStack, upgradedStack, materials } = event;
    if (!player || !player.getServer()) return;
    if (level.clientSide || !targetStack || !upgradedStack) return

    let hilt_module = upgradedStack.getItem().getModuleFromSlot(upgradedStack, 'sword/hilt')
    if (!hilt_module) return

    let module_key = hilt_module.key
    if (module_key !== 'sword/candy_cane') return
    for (let key of sweetish_fish_keys) {
        if (!dzzl_has_improvement(hilt_module, upgradedStack, key)) {
            return
        }
    }


    sweetish_fish_keys.forEach(key => {
        hilt_module.removeImprovement(upgradedStack, key)
    })
    hilt_module.addImprovement(upgradedStack, 'candycaneallsweetishfish', 0)


})

const candy_cane_keys = [
    "candy_cane/candy_cane/candy_cane_block",
    "candy_cane/candy_cane/chiseled_candy_cane_block",
    "candy_cane/candy_cane/stripped_candy_cane_block",
    "candy_cane/candy_cane/candy_cane_pole",
    "candy_cane/candy_cane/stripped_candy_cane_pole"
];

TetraJSEvents.workbenchCraft(event => {
    let { player, level, currentSchematic, currentSlot, targetStack, upgradedStack, materials } = event;
    if (!player || !player.getServer()) return;
    if (level.clientSide || !targetStack || !upgradedStack) return;

    let hilt_module = upgradedStack.getItem().getModuleFromSlot(upgradedStack, 'sword/hilt');
    if (!hilt_module) return;

    let module_key = hilt_module.key;
    if (module_key !== 'sword/candy_cane') return
    for (let key of candy_cane_keys) {
        if (!dzzl_has_improvement(hilt_module, upgradedStack, key)) {
            return;
        }
    }


    candy_cane_keys.forEach(key => {
        hilt_module.removeImprovement(upgradedStack, key);
    });
    hilt_module.addImprovement(upgradedStack, 'candycaneallcandycane', 0);

})

const rock_candy_keys = [
    "candy_cane/rock_candy/rock_candy_orange",
    "candy_cane/rock_candy/rock_candy_magenta",
    "candy_cane/rock_candy/rock_candy_light_blue",
    "candy_cane/rock_candy/rock_candy_yellow",
    "candy_cane/rock_candy/rock_candy_green",
    "candy_cane/rock_candy/rock_candy_red",
    "candy_cane/rock_candy/rock_candy_black",
    "candy_cane/rock_candy/rock_candy_gray",
    "candy_cane/rock_candy/rock_candy_white",
    "candy_cane/rock_candy/rock_candy_brown",
    "candy_cane/rock_candy/rock_candy_blue",
    "candy_cane/rock_candy/rock_candy_purple",
    "candy_cane/rock_candy/rock_candy_cyan",
    "candy_cane/rock_candy/rock_candy_light_gray",
    "candy_cane/rock_candy/rock_candy_lime",
    "candy_cane/rock_candy/rock_candy_pink"
];

TetraJSEvents.workbenchCraft(event => {
    let { player, level, currentSchematic, currentSlot, targetStack, upgradedStack, materials } = event;
    if (!player || !player.getServer()) return;
    if (level.clientSide || !targetStack || !upgradedStack) return;

    let hilt_module = upgradedStack.getItem().getModuleFromSlot(upgradedStack, 'sword/hilt');
    if (!hilt_module) return;

    let module_key = hilt_module.key;
    if (module_key !== 'sword/candy_cane') return
    for (let key of rock_candy_keys) {
        if (!dzzl_has_improvement(hilt_module, upgradedStack, key)) {
            return;
        }
    }


    rock_candy_keys.forEach(key => {
        hilt_module.removeImprovement(upgradedStack, key);
    });
    hilt_module.addImprovement(upgradedStack, 'candycaneallrockcandy', 0);

});