// priority: 4

onEvent('item.tooltip', tooltip => {

    /*colors
    §1 - dark blue
    §2 - dark green
    §3 - dark aqua
    §4 - dark red
    §5 - purple
    §6 - orange
    §7 - gray
    §8 - dark gray
    §9 - blue
    §0 - black
    §a - light green
    §b - light aqua
    §c - light red
    §d - pink
    §e - light yellow
    §f - white*/

    function createTooltips(id, summary, controls) {
        summary = summary ? summary : {}
        controls = controls ? controls : {}
        const { mat, specDmg, dur, pas, set } = summary
        const { rmbClick, rmbHold, rmbSneak, rmbBlock, ctrlHold, pressX, shiftX, space } = controls

        tooltip.addAdvanced(id, (item, advanced, text) => {
            let iteration = 1

            if (!tooltip.shift) {
                text.add(iteration++, [Text.darkGray('Hold ['), Text.gray('Shift'), Text.darkGray('] for Summary')])
            } else {
                text.add(iteration++, [Text.darkGray('Hold ['), Text.white('Shift'), Text.darkGray('] for Summary')])
                text.add(iteration++, [""])

                if (pas) {
                    text.add(iteration++, [Text.gray('Passive Ability: '), Text.gold(pas)])
                }

                if (specDmg) {
                    text.add(iteration++, [`§7Special Damage: §6${specDmg}`])
                }

                if (set) {
                    text.add(iteration++, [`§7Armor Set Bonuses: ${set}`])
                }

                if (mat) {
                    text.add(iteration++, [Text.gray('Repair Material: '), Text.gold(mat)])
                }

                text.add(iteration++, [Text.gray('Durability: '), Text.gold(dur ? dur : "Infinite")])
            }
            if (Object.keys(controls).length) {
                if (!tooltip.ctrl) {
                    text.add(iteration++, [Text.darkGray('Hold ['), Text.gray('Ctrl'), Text.darkGray('] for Controls')])
                } else {
                    text.add(iteration++, [Text.darkGray('Hold ['), Text.white('Ctrl'), Text.darkGray('] for Controls')])
                    text.add(iteration++, [""])

                    if (rmbClick) {
                        text.add(iteration++, [`§7Right-Click`])
                        rmbClick.forEach(line => {
                            text.add(iteration++, [` §4${line}`])
                        })
                    }

                    if (rmbHold) {
                        text.add(iteration++, [`§7Hold Right-Click`])
                        rmbHold.forEach(line => {
                            text.add(iteration++, [` §4${line}`])
                        })
                    }

                    if (rmbSneak) {
                        text.add(iteration++, [`§7R-Click while Sneaking`])
                        rmbSneak.forEach(line => {
                            text.add(iteration++, [` §4${line}`])
                        })
                    }

                    if (rmbBlock) {
                        text.add(iteration++, [`§7Right-Click a block`])
                        rmbBlock.forEach(line => {
                            text.add(iteration++, [` §4${line}`])
                        })
                    }

                    if (ctrlHold) {
                        text.add(iteration++, [`§7Hold Ctrl`])
                        ctrlHold.forEach(line => {
                            text.add(iteration++, [` §4${line}`])
                        })
                    }

                    if (pressX) {
                        text.add(iteration++, [`§7Press "X"`])
                        pressX.forEach(line => {
                            text.add(iteration++, [` §4${line}`])
                        })
                    }

                    if (shiftX) {
                        text.add(iteration++, [`§7Press "Shift + X"`])
                        shiftX.forEach(line => {
                            text.add(iteration++, [` §4${line}`])
                        })
                    }

                    if (space) {
                        text.add(iteration++, [`§7Press "Space"`])
                        space.forEach(line => {
                            text.add(iteration++, [` §4${line}`])
                        })
                    }
                }
            }
        })
    }



    //swords
    createTooltips('avaritia:skullfire_sword', { mat: 'Coal Coke', dur: "3000" })
    createTooltips('superior_swords:evil_sword', { mat: 'Charged Certus Quartz Crystal', dur: "2000", pas: "Inflicts §c\"Blindness\"§6 on target" })
    createTooltips('superior_swords:nature_sword', { mat: 'Sky Dust', dur: "4000", pas: "Resistace II" })
    createTooltips('yet_another_lightning_sword:lightningswordtool', { mat: 'End Rod', dur: "3000", pas: "§c8%§6 chance to strike lightning" })
    createTooltips('superior_swords:cloud_sword', { mat: 'Bottled Cloud', dur: "5000", pas: "Inflicts §c\"Levitation\"§6 and §c\"Glowing\"§6 on target" })
    createTooltips('wstweaks:lava_blade', { mat: 'Redstone Ingot', specDmg: 'Fire', dur: "4000" })
    createTooltips(
        'superior_swords:sword_of_skylord',
        { mat: 'Singularity', dur: "6000", pas: "Inflicts §c\"Levitation\"§6 on target" }, {
            rmbClick: [
                "Gives §c\"Levitation II\"§4 effect to the sword's holder for §c7 seconds§4."
            ]
        }
        )
    createTooltips('superior_swords:soul_sword', { mat: 'Shadow Steel', specDmg: 'Wither', dur: "5000" })
    createTooltips('superior_swords:wither_sword', { mat: 'Refined Radiance', specDmg: 'Wither', dur: "7000", pas: "Resistace II" })
    createTooltips('superior_swords:weak_dragon_sword', { mat: 'Coagulated Blood', specDmg: 'Bleeding', dur: "6000" })
    createTooltips('wstweaks:blaze_blade', { mat: 'Singularity', specDmg: 'Fire', dur: "8000" })
    createTooltips(
        'superior_swords:weak_god_sword',
        { mat: 'Computation Matrix', dur: "7000", pas: "Speed II, Resistance III" }, {
            rmbClick: [
                "Casts a §cmassive§4 lightning strike on the sword's holder,",
                "causing §cAOE damage§4 to the player and nearby mobs.",
                "If player is strong enough to survive the explosion,",
                "they will receive the following buffs for §c45 seconds§4:",
                "§cStrenght III, Speed II, Resistance II, Regeneration II,",
                "§cLuck II, Jump Boost III, Slow Falling II.",
            ]
        }
    )
    createTooltips(
        'superior_swords:oceanic_sword',
        { mat: 'Computation Matrix', dur: "9000" }, {
            rmbClick: [
                "Casts §c\"Regeneration II\"§4 effect on the sword's holder for §c4 seconds§4,",
                "making the player §cheal 4 health§4 in cost of §c1 durability§4."
            ]
        }
    )
    createTooltips('miniutilities:kikoku', { specDmg: 'Divine, Soul, Armor Piercing' })
    createTooltips(/miniutilities:(healing|reversing|destruction|erosion|etheric|precision)_(sword|shovel|(pick)?axe|hoe|shears)/)
    createTooltips(/projecte:dm_(sword|shovel|axe|hoe|shears|hammer)/)
    createTooltips(/projectextended:dark_matter_.*/)
    createTooltips(/projecte:rm_(sword|shovel|axe|hoe|shears|hammer|katar|morning_star)/)
    createTooltips(/projectextended:red_matter_.*/)
    createTooltips(/industrialforegoing:infinity_.*[^charger]/, { mat: "Electricity", dur: "Electrical" })
    createTooltips(/avaritia:(swordofthe_cosmos|hoeofthe_green_earth|natures_ruin|longbowofthe_heavens|planet_eater|world_breaker)/)
    createTooltips(
        'cataclysm:the_incinerator', {}, {
            rmbHold: [
                "Release (after §c3 seconds§4) to summon a §cflame strike§4.",
                "§cWARNING: §4Sword may be lost as the flame strike explodes when it disappears.",
            ]
        }
    )
    createTooltips('cataclysm:final_fractal', { pas: "Causes additional damage (§c3%§6 of target's max HP)" })
    createTooltips('cataclysm:zweiender', { pas: "Attacking target's back deals §c100%§6 more damage" })
    createTooltips("mekanism:atomic_disassembler", { mat: "Electricity", dur: "Electrical" })



    //bows
    createTooltips("morebows:diamond_bow", { mat: "Charged Certus Quartz Crystal", dur: "3000" })
    createTooltips("morebows:frost_bow", { mat: "Blue Ice", dur: "4000", specDmg: "Cold" })
    createTooltips("morebows:flame_bow", { mat: "Blaze Powder", dur: "5000", specDmg: "Fire" })
    createTooltips("morebows:multi_bow", { mat: "Computation Matrix", dur: "7000", pas: "Shoots 2 arrows at once, spends only 1" })
    createTooltips("morebows:ender_bow", { mat: "Endest Pearl", dur: "10000", pas: "Shoots 5 additional arrows in the same direction" })
    createTooltips("mekanism:electric_bow", { mat: "Electricity", dur: "Electrical" })



    //tools
    createTooltips('cataclysm:gauntlet_of_guard', {}, { rmbHold: ["§cWhen in main hand: §4Pulls enemies towards you like a magnet"] })
    createTooltips('cataclysm:bulwark_of_the_flame', {}, { rmbSneak: [
        "Release while sneaking to §ccharge forward§4 and deal damage to enemies.",
        "If target get hit by wall, it will take §cdouble§4 damage and will be §cstunned§4.",
    ] })
    createTooltips('cataclysm:infernal_forge', {}, { rmbBlock: [
        "§cWhen in main hand: §4deals §c100%§4 of weapon",
        "damage as §cAOE§4 damage in a small raidus.",
    ] })
    createTooltips('cataclysm:void_core', {}, { rmbBlock: [
        "Summons void rune in the direcion you're looking.",
    ] })
    createTooltips('projecte:dm_pick', { pas: "Allows destroying §eDark Matter§6 blocks" })
    createTooltips('projecte:rm_pick', { pas: "Allows destroying §eDark & Red Matter§6 blocks" })



    //armor sets
    createTooltips(/immersive_armors:divine_(helmet|chestplate|leggings|boots)/, { mat: "Coal Coke", set: "§eGlowing, §c100% §6chance to deflect 1 hit per 1 minute", dur: "1000" })
    createTooltips(/immersive_armors:bone_(helmet|chestplate|leggings|boots)/, { mat: "Bone", set: "§9Speed I, §6Skeletons & Wither Skeletons won't attack you", dur: "2000" })
    createTooltips(/immersive_armors:wither_(helmet|chestplate|leggings|boots)/, { mat: "Necrotic Bone", set: "§5\"Wither\" §6effect to attacker, §6Skeletons & Wither Skeletons won't attack you", dur: "3000" })
    createTooltips(/immersive_armors:prismarine_(helmet|chestplate|leggings|boots)/, { mat: "Prismarine Shard", pas: "+1 Spike Damage, Depth Strider I", set: "§bWater Breathing, §9Speed I", dur: "4000" })

    createTooltips("immersive_armors:steampunk_helmet", { mat: "Cogwheels", pas: "+10% Explosion Resistance", set: "§9Speed II, §aLuck I", dur: "5000" }, { ctrlHold: ["Simple entity radar that §chighlights enemies §4around you."]})
    createTooltips("immersive_armors:steampunk_chestplate", { mat: "Cogwheels", pas: "+10% Explosion Resistance", set: "§9Speed II, §aLuck I", dur: "5000" })
    createTooltips("immersive_armors:steampunk_leggings", { mat: "Cogwheels", pas: "+10% Explosion Resistance", set: "§9Speed II, §aLuck I", dur: "5000" }, { space: ["While in the air to make §cdouble jump§4!"]})
    createTooltips("immersive_armors:steampunk_boots", { mat: "Cogwheels", pas: "§7Steam Falling, §6+10% Explosion Resistance", set: "§9Speed II, §aLuck I", dur: "5000" })

    createTooltips(/immersive_armors:robe_(helmet|chestplate|leggings|boots)/, { mat: "Computation Matrix", set: "§aNight Vision, §9Speed I", specDmg: "+0.5sec fire damage to attacker", pas: "+25% Fire Resistance, +20% Magic Resistance", dur: "6000" })
    createTooltips(/miniutilities:infused_(helmet|chestplate|leggings|boots)/, { set: "§3Resistance II, §9Speed II" })
    createTooltips(/miniutilities:unstable_(helmet|chestplate|leggings|boots)/, { set: "§9Speed III, §3Jump Boost II" })
    createTooltips(/projecte:dm_(helmet|chestplate|leggings|boots)/, { set: "§6Fire Resistance I, §3Resistance II, §9Speed II" })
    createTooltips(/projecte:rm_(helmet|chestplate|leggings|boots)/, { set: "§6Fire Resistance II, §3Resistance III, §9Speed II" })
    createTooltips("projecte:gem_helmet", { pas: "§bWater Breathing" }, { shiftX: ["Toggles §cNight Vision§4."] })
    createTooltips("projecte:gem_chestplate", { pas: "§6Fire Resistance IV" })
    createTooltips("projecte:gem_leggings", { pas: "§5Feather Falling IV" })
    createTooltips("projecte:gem_boots", { pas: "§9Speed II" }, { pressX: ["Toggles §cStep Assist§4."], space: ["Toggles §cCreative Flight§4."] })
    createTooltips(/mekanism:hazmat_(mask|gown|pants|boots)/, { set: "§6Fire Resistance II, §3Resistance II" })

    createTooltips("cataclysm:ignitium_helmet", { pas: "Lava Vision", set: "§6Fire Resistance IV, §9Speed II" })
    createTooltips("cataclysm:ignitium_chestplate", { set: "§6Fire Resistance IV, §9Speed II" })
    createTooltips("cataclysm:ignitium_elytra_chestplate", { set: "§6Fire Resistance IV, §9Speed II" })
    createTooltips("cataclysm:ignitium_leggings", { pas: "Flame Reflex", set: "§6Fire Resistance IV, §9Speed II" })
    createTooltips("cataclysm:ignitium_boots", { pas: "Lava Walker", set: "§6Fire Resistance IV, §9Speed II" })

    createTooltips(/avaritia:infinity_armor_(helmet|chestplate|leggings|boots)/, { set: "§dEvery Positive Effect (Maximized)" })



    //shields
    createTooltips("shieldexp:paragon_shield", { mat: "Singularity", dur: "2000" })
    createTooltips("shieldexp:griefer_shield", { mat: "Computation Matrix", dur: "4000" })
})