let TooltipRegistries = Java.loadClass("net.yiran.extraholopage.api.TooltipRegistries")
let I18n = Java.loadClass("net.minecraft.client.resources.language.I18n")

// 按键
let isKeyPressed = false
NewKeyBindEvents.isPressInGui('key.mainhand_effect', event => {
    isKeyPressed = true
})
NewKeyBindEvents.isReleaseInGui('key.mainhand_effect', event => {
    isKeyPressed = false
})
// console.log(KeyBindUtil.getAllKeyName())
// 注册用
function registerTooltip(effectName, tooltipSuffix) {
    // 默认后缀 tooltip_short
    if (tooltipSuffix === undefined) {
        tooltipSuffix = ".tooltip_short"
    }
    TooltipRegistries.register(
        effectName,
        (effect, level, level2) => {
            if (isKeyPressed) {
                let effectNameCat = "tetra.stats." + effectName
                let effectTooltip = effectNameCat + tooltipSuffix
                let text = "§f" + I18n.get(effectNameCat) + " : §r" + "\n§7[§r " +
                          I18n.get(effectTooltip, level, level2) + " §7]§r"
                return Component.literal(text)
            } else {
                return TooltipRegistries.defaultGetter(effect, level, level2)
            }
        }
    )
}

// 注册 global 里的
if (global.all_effect) {
    global.all_effect.forEach(item => {
        registerTooltip(item.effect_name, ".tooltip")
    })
}

// 注册不在 global 里的
//* tetra本体的effect
let tetra = [
    "tetra.stats.reach",
    "tetra.stats.attack_range",
    "tetra.stats.durability",
    "tetra.stats.speed",
    "tetra.stats.draw_speed",
    "tetra.stats.draw_speed_normalized",
    "tetra.stats.ability_speed",
    "tetra.stats.ability_speed_normalized",
    "tetra.stats.speed_normalized",
    "tetra.stats.attack_damage",
    "tetra.stats.attack_damage_normalized",
    "tetra.stats.draw_strength",
    "tetra.stats.power",
    "tetra.stats.quick_charge",
    "tetra.stats.ability_damage",
    "tetra.stats.bleeding",
    "tetra.stats.backstab",
    "tetra.stats.armor",
    "tetra.stats.toughness",
    "tetra.stats.shieldbreaker",
    "tetra.stats.blocking",
    "tetra.stats.blocking_reflect",
    "tetra.stats.bashing",
    "tetra.stats.throwable",
    "tetra.stats.ricochet",
    "tetra.stats.piercing",
    "tetra.stats.piercing_harvest",
    "tetra.stats.jab",
    "tetra.stats.armorPenetration",
    "tetra.stats.crushing",
    "tetra.stats.skewering",
    "tetra.stats.stun",
    "tetra.stats.howling",
    "tetra.stats.ability_speed_bonus",
    "tetra.stats.ability_defensive",
    "tetra.stats.ability_overcharge",
    "tetra.stats.ability_momentum",
    "tetra.stats.ability_combo",
    "tetra.stats.ability_overextend",
    "tetra.stats.ability_exhilaration",
    "tetra.stats.ability_revenge",
    "tetra.stats.execute_revenge",
    "tetra.stats.puncture_revenge",
    "tetra.stats.ability_echo",
    "tetra.stats.execute",
    "tetra.stats.severing",
    "tetra.stats.lunge",
    "tetra.stats.slam",
    "tetra.stats.puncture",
    "tetra.stats.overpower",
    "tetra.stats.reap",
    "tetra.stats.pry_armor",
    "tetra.stats.knockback",
    "tetra.stats.looting",
    "tetra.stats.fiery",
    "tetra.stats.sharpness",
    "tetra.stats.smite",
    "tetra.stats.arthropod",
    "tetra.stats.sweeping",
    "tetra.stats.truesweep",
    "tetra.stats.unbreaking",
    "tetra.stats.mending",
    "tetra.stats.silkTouch",
    "tetra.stats.replanting",
    "tetra.stats.fortune",
    "tetra.stats.flame",
    "tetra.stats.punch",
    "tetra.stats.infinity",
    "tetra.stats.quickStrike",
    "tetra.stats.counterweight",
    "tetra.stats.softStrike",
    "tetra.stats.fierySelf",
    "tetra.stats.enderReverb",
    "tetra.stats.sculkTaint",
    "tetra.stats.toolbelt.quickslot",
    "tetra.stats.toolbelt.potion_storage",
    "tetra.stats.toolbelt.storage",
    "tetra.stats.toolbelt.quiver",
    "tetra.stats.toolbelt.booster",
    "tetra.stats.toolbelt.suspend_self",
    "tetra.stats.bow.releaseLatch",
    "tetra.stats.bow.overbowed",
    "tetra.stats.multishot",
    "tetra.stats.zoom",
    "tetra.stats.spread",
    "tetra.stats.focus",
    "tetra.stats.focusEcho",
    "tetra.stats.velocity",
    "tetra.stats.suspend",
    "tetra.stats.criticalStrike",
    "tetra.stats.holo_speed",
    "tetra.stats.holo.sweeperRange",
    "tetra.stats.holo.sweeperHorizontalSpread",
    "tetra.stats.holo.sweeperVerticalSpread",
    "tetra.stats.holo.percussionScanner",
    "tetra.stats.intuit",
    "tetra.stats.earthbind",
    "tetra.stats.reaching",
    "tetra.stats.tool.reaching_sweeping",
    "tetra.stats.janking",
    "tetra.stats.magicCapacity",
    "tetra.stats.stability",
    "tetra.stats.stabilizing",
    "tetra.stats.unstable",
    "tetra.stats.workable",
    "tetra.stats.tool.breakdown",
    "tetra.stats.tool.enchantment_bonus",
    "tetra.stats.tool.striking",
    "tetra.stats.tool.sweeping",
    "tetra.stats.tool.truesweepingStrike",
    "tetra.stats.tool.planarSweep",
    "tetra.stats.tool.sweepingFocus",
    "tetra.stats.tool.extraction",
    "tetra.stats.tool.unboundExtraction",
    "tetra.stats.medialLimit",
    "tetra.stats.lateralLimit",
    "tetra.stats.axialLimit",
    "tetra.stats.integrity",
    "tetra.stats.integrity_usage"
]

tetra.forEach(effectPath => {
    let effectName = effectPath.split('.').pop()
    registerTooltip(effectName, ".tooltip")
})