//Priority: 1
/**
 * @file        jei_add_tooltip.js
 * @description ITEM TOOLTIP SCRIPT  
 * @modpack     Monumental Experience
 * @author      KnightDexx
 * @version     1.0 
 * @copyright   KnightDexx's Modded Minecraft World
 * @license     All Rights Reserved
 */
ItemEvents.tooltip(event => {
    // ---------------------------------------------------------------------------
    // Duplicate-immune helpers
    // ---------------------------------------------------------------------------
    // Fingerprint of a tooltip line (single Component or array of Components)
    function lineKey(line) {
        if (line instanceof Array) {
            return line.map(function(c) {
                return String(c.getString ? c.getString() : c)
            }).join('')
        }
        return String(line.getString ? line.getString() : line)
    }
    // Add lines only if they are not already present in the tooltip.
    // Optional index preserves original insertion position (e.g. below item name).
    function addSafe(id, lines, index) {
        if (!(lines instanceof Array)) lines = [lines]
        event.addAdvanced(id, function(stack, advanced, text) {
            var existing = []
            for (var i = 0; i < text.size(); i++) {
                existing.push(lineKey(text.get(i)))
            }
            lines.forEach(function(line) {
                var key = lineKey(line)
                if (existing.includes(key)) return
                if (index === undefined) {
                    text.add(line)
                } else {
                    text.add(index, line)
                }
                existing.push(key)
            })
        })
    }
    // ---------------------------------------------------------------------------
    // Helpers
    // ---------------------------------------------------------------------------
    // 1) One text for all Eccentric Tome books
    function addTomeBookTooltip(id) {
        addSafe(id, [Text.of('This book is already included within your Eccentric Tome').yellow()])
    }
    // 2) "Players Only / Not Automatable" for watering cans
    function addWateringCanTooltip(id) {
        addSafe(id, [
            [Text.of('Players Only').green()],
            [Text.of('Not Automatable').darkGreen()]
        ])
    }
    // ---------------------------------------------------------------------------
    // Eccentric Tome Books
    // ---------------------------------------------------------------------------
    ;
    ['patchouli:guide_book', 'blue_skies:blue_journal', 'alexsmobs:animal_dictionary', 'alexscaves:cave_book', 'ftbquests:book', 'immersiveengineering:manual', 'botania:lexicon', 'rftoolsbase:manual', 'forestry:foresters_manual', 'cookingforblockheads:recipe_book', 'solcarrot:food_book', 'securitycraft:sc_manual', 'croptopia:guide', 'enigmaticlegacy:the_acknowledgment', 'eidolon_repraised:codex', 'ae2:guide', 'actuallyadditions:booklet'].forEach(addTomeBookTooltip)
    // ---------------------------------------------------------------------------
    // Allthemodium
    // ---------------------------------------------------------------------------
    addSafe('allthemodium:teleport_pad', [
        Text.of('Place the pad down in the specified Dimension'),
        Text.of('Sneak Right Click with both hands empty to teleport'),
        Text.of('§aOverworld to Mining Dimension'),
        Text.of('§cThe Nether to The Other'),
        Text.of('§dThe End to The Beyond')
    ])
    // ---------------------------------------------------------------------------
    // Mystical Agriculture
    // ---------------------------------------------------------------------------
    ;
    ['mysticalagriculture:watering_can', 'mysticalagriculture:inferium_watering_can', 'mysticalagriculture:prudentium_watering_can', 'mysticalagriculture:tertium_watering_can', 'mysticalagriculture:imperium_watering_can'].forEach(addWateringCanTooltip)
    addSafe('mysticalagriculture:creative_soulium_dagger', [
        Text.of('Obtained by defeating the Dark Mask Boss').green()
    ])
    // ---------------------------------------------------------------------------
    // RS Infinity Booster
    // ---------------------------------------------------------------------------
    addSafe('rsinfinitybooster:infinity_card', [
        Text.of('Infinite range for RS wireless'),
        Text.of('Only works in the same dimension')
    ])
    addSafe('rsinfinitybooster:dimension_card', [
        Text.of('Infinite range for RS wireless'),
        Text.of('Works across dimensions')
    ])
    // ---------------------------------------------------------------------------
    // Pipez
    // ---------------------------------------------------------------------------
    addSafe('pipez:item_pipe', [
        [Text.of('Default:'), ' ', Text.of('4'), ' ', Text.of('items/20t')],
        [Text.of('Basic:'), ' ', Text.of('8'), ' ', Text.of('items/15t')],
        [Text.of('Improved:').gold(), ' ', Text.of('16').yellow(), ' ', Text.of('items/10t').gold()],
        [Text.of('Advanced:').darkAqua(), ' ', Text.of('32').aqua(), ' ', Text.of('items/5t').darkAqua()],
        [Text.of('Ultimate:').darkGray(), ' ', Text.of('64').gray(), ' ', Text.of('items/t').darkGray()],
        [Text.of('Infinity:').darkPurple(), ' ', Text.of('2,147,483,647').lightPurple(), ' ', Text.of('items/t').darkPurple()]
    ])
    addSafe('pipez:fluid_pipe', [
        [Text.of('Default:'), ' ', Text.of('50'), ' ', Text.of('mB/t')],
        [Text.of('Basic:'), ' ', Text.of('100'), ' ', Text.of('mB/t')],
        [Text.of('Improved:').gold(), ' ', Text.of('500').yellow(), ' ', Text.of('mB/t').gold()],
        [Text.of('Advanced:').darkAqua(), ' ', Text.of('2,000').aqua(), ' ', Text.of('mB/t').darkAqua()],
        [Text.of('Ultimate:').darkGray(), ' ', Text.of('10,000').gray(), ' ', Text.of('mB/t').darkGray()],
        [Text.of('Infinity:').darkPurple(), ' ', Text.of('2,147,483,647').lightPurple(), ' ', Text.of('mB/t').darkPurple()]
    ])
    addSafe('pipez:gas_pipe', [
        [Text.of('Default:'), ' ', Text.of('200'), ' ', Text.of('mB/t')],
        [Text.of('Basic:'), ' ', Text.of('400'), ' ', Text.of('mB/t')],
        [Text.of('Improved:').gold(), ' ', Text.of('2,000').yellow(), ' ', Text.of('mB/t').gold()],
        [Text.of('Advanced:').darkAqua(), ' ', Text.of('8,000').aqua(), ' ', Text.of('mB/t').darkAqua()],
        [Text.of('Ultimate:').darkGray(), ' ', Text.of('40,000').gray(), ' ', Text.of('mB/t').darkGray()],
        [Text.of('Infinity:').darkPurple(), ' ', Text.of('2,147,483,647').lightPurple(), ' ', Text.of('mB/t').darkPurple()]
    ])
    addSafe('pipez:energy_pipe', [
        [Text.of('Default:'), ' ', Text.of('256'), ' ', Text.of('FE/t')],
        [Text.of('Basic:'), ' ', Text.of('1,024'), ' ', Text.of('FE/t')],
        [Text.of('Improved:').gold(), ' ', Text.of('8,192').yellow(), ' ', Text.of('FE/t').gold()],
        [Text.of('Advanced:').darkAqua(), ' ', Text.of('32,768').aqua(), ' ', Text.of('FE/t').darkAqua()],
        [Text.of('Ultimate:').darkGray(), ' ', Text.of('131,072').gray(), ' ', Text.of('FE/t').darkGray()],
        [Text.of('Infinity:').darkPurple(), ' ', Text.of('2,147,483,647').lightPurple(), ' ', Text.of('FE/t').darkPurple()]
    ])
    // Upgrades
    addSafe('pipez:basic_upgrade', [
        [Text.of('Item:'), ' ', Text.of('8'), ' ', Text.of('items/t')],
        [Text.of('Fluid:'), ' ', Text.of('100'), ' ', Text.of('mB/t')],
        [Text.of('Gas:'), ' ', Text.of('400'), ' ', Text.of('mB/t')],
        [Text.of('Energy:'), ' ', Text.of('1,024'), ' ', Text.of('FE/t')]
    ])
    addSafe('pipez:improved_upgrade', [
        [Text.of('Item:').gold(), ' ', Text.of('16').yellow(), ' ', Text.of('items/t').gold()],
        [Text.of('Fluid:').gold(), ' ', Text.of('500').yellow(), ' ', Text.of('mB/t').gold()],
        [Text.of('Gas:').gold(), ' ', Text.of('2,000').yellow(), ' ', Text.of('mB/t').gold()],
        [Text.of('Energy:').gold(), ' ', Text.of('8,192').yellow(), ' ', Text.of('FE/t').gold()]
    ])
    addSafe('pipez:advanced_upgrade', [
        [Text.of('Item:').darkAqua(), ' ', Text.of('32').aqua(), ' ', Text.of('items/t').darkAqua()],
        [Text.of('Fluid:').darkAqua(), ' ', Text.of('2,000').aqua(), ' ', Text.of('mB/t').darkAqua()],
        [Text.of('Gas:').darkAqua(), ' ', Text.of('8,000').aqua(), ' ', Text.of('mB/t').darkAqua()],
        [Text.of('Energy:').darkAqua(), ' ', Text.of('32,768').aqua(), ' ', Text.of('FE/t').darkAqua()]
    ])
    addSafe('pipez:ultimate_upgrade', [
        [Text.of('Item:').darkGray(), ' ', Text.of('64').gray(), ' ', Text.of('items/t').darkGray()],
        [Text.of('Fluid:').darkGray(), ' ', Text.of('10,000').gray(), ' ', Text.of('mB/t').darkGray()],
        [Text.of('Gas:').darkGray(), ' ', Text.of('40,000').gray(), ' ', Text.of('mB/t').darkGray()],
        [Text.of('Energy:').darkGray(), ' ', Text.of('131,072').gray(), ' ', Text.of('FE/t').darkGray()]
    ])
    addSafe('pipez:infinity_upgrade', [
        [Text.of('Item:').darkPurple(), ' ', Text.of('2,147,483,647').lightPurple(), ' ', Text.of('items/t').darkPurple()],
        [Text.of('Fluid:').darkPurple(), ' ', Text.of('2,147,483,647').lightPurple(), ' ', Text.of('mB/t').darkPurple()],
        [Text.of('Gas:').darkPurple(), ' ', Text.of('2,147,483,647').lightPurple(), ' ', Text.of('mB/t').darkPurple()],
        [Text.of('Energy:').darkPurple(), ' ', Text.of('2,147,483,647').lightPurple(), ' ', Text.of('FE/t').darkPurple()]
    ])
    // ---------------------------------------------------------------------------
    // EnderStorage
    // ---------------------------------------------------------------------------
    const enderChestText = [
        [Text.of('Cross-dimensional wireless item transfer to any chest on the same channel.').gold()],
        [Text.of('Use dye on the colored bars to set the channel.').gold()],
        [Text.of('Use a diamond on the latch to switch to private channel.').gold()]
    ]
    addSafe('enderstorage:ender_chest', enderChestText)
    addSafe('enderstorage:ender_tank', enderChestText)
    // ---------------------------------------------------------------------------
    // Enigmatic Legacy / Midnight Madness / Apotheotic Additions
    // ---------------------------------------------------------------------------
    // Heart of the Earth
    addSafe('enigmaticlegacy:earth_heart', [
        [Text.of('100% drop chance by killing a Wither.').gold()],
        [Text.of('10% drop chance by killing Vex.').gold()],
        [Text.of('5% drop chance by killing Wither Skeleton.').gold()]
    ])
    // Heart of the Abyss
    addSafe('enigmaticlegacy:abyssal_heart', [
        Text.of('100% drop chance by killing a Warden.').gold()
    ])
    // Apotheotic Additions coins
    const apotheoticCoinText = [
        [Text.of('Apotheotic coins are located in rogue spawners,').green()],
        [Text.of('they can also be traded from the Wandering Trader.').green()]
    ]
    addSafe('apotheotic_additions:apotheotic_coin', apotheoticCoinText)
    addSafe('apotheotic_additions:infused_coin', apotheoticCoinText)
    addSafe('apotheotic_additions:ascended_coin', apotheoticCoinText)
    // ---------------------------------------------------------------------------
    // End Remastered
    // ---------------------------------------------------------------------------
    addSafe('endrem:undead_soul', [
        Text.of('50% drop chance by killing a Skeleton Horse.').green()
    ])
    addSafe('endrem:witch_pupil', [
        Text.of('35% drop chance by killing a Witch.').green()
    ])
    addSafe('endrem:magical_eye', [
        [Text.of('25% drop chance by killing a Evoker.').green()],
        [Text.of('15% chance of being found in Mansion treasure chests.').green()]
    ])
    addSafe('endrem:guardian_eye', [
        Text.of('40% drop chance by killing a Elder Guardian.').green()
    ])
    addSafe('endrem:wither_eye', [
        Text.of('99% drop chance by killing a Wither.').green()
    ])
    addSafe('endrem:lost_eye', [
        [Text.of('20% chance of being found in Mineshafts treasure chest.').green()],
        [Text.of('5% chance of being found in Dungeons treasure chests.').green()]
    ])
    addSafe('endrem:cursed_eye', [
        Text.of('20% chance of being found in Bastions treasure chest.').green()
    ])
    addSafe('endrem:black_eye', [
        [Text.of('30% chance of being found in Buried treasure chests.').green()],
        [Text.of('25% chance of being found in Shipwreck treasure chests.').green()]
    ])
    addSafe('endrem:old_eye', [
        [Text.of('25% chance of being found in Desert Pyramids treasure chests.').green()],
        [Text.of('5% chance of being found in Dungeons treasure chests.').green()]
    ])
    addSafe('endrem:cold_eye', [
        Text.of('65% chance of being found in Igloos treasure chests.').green()
    ])
    addSafe('endrem:rogue_eye', [
        Text.of('45% chance of being found in Jungle Temples treasure chests.').green()
    ])
    addSafe('endrem:corrupted_eye', [
        Text.of('35% chance of being found in Pillager Outposts treasure chests.').green()
    ])
    addSafe('endrem:nether_eye', [
        Text.of('25% chance of being found in Nether Fortress treasure chests.').green()
    ])
    // ---------------------------------------------------------------------------
    // Refined Storage – NBT items warning
    // ---------------------------------------------------------------------------
    let warningMessageLine1 = 'Warning: Please do not store too many NBT items.'
    let warningMessageLine2 = 'Use external storage for tools, weapons, armor, etc.'
    let storageParts = ['refinedstorage:1k_storage_part', 'refinedstorage:4k_storage_part', 'refinedstorage:16k_storage_part', 'refinedstorage:64k_storage_part', 'extradisks:256k_storage_part', 'extradisks:1024k_storage_part', 'extradisks:4096k_storage_part', 'extradisks:16384k_storage_part', 'extradisks:65536k_storage_part', 'extradisks:262144k_storage_part', 'extradisks:1048576k_storage_part', 'extradisks:infinite_storage_part'];
    storageParts.forEach(part => {
        addSafe(part, [
            [Text.of(warningMessageLine1).darkRed()],
            [Text.of(warningMessageLine2).lightPurple()]
        ])
        // ---------------------------------------------------------------------------
        // Minecraft Vanilla
        // ---------------------------------------------------------------------------
        addSafe('minecraft:smithing_table', [
            [Text.of('The default recipe for this item has been disabled and can now be discovered through exploration.').gold()],
        ])
        addSafe('minecraft:obsidian', [
            [Text.of('The default way to make a nether portal by lighting an Obsidian frame is disabled. Please use the Nether Painting from Dim Painting!').gold()],
        ])
        addSafe('minecraft:bucket', [
            [Text.of('Most buckets can be condensed! Crouch-right-click to change modes.').gold()],
            [Text.of('Filling acts as a normal bucket; you need buckets in your off-hand.').gold()],
            [Text.of('Emptying acts as a normal filled bucket; your buckets are refunded.').gold()],
            [Text.of('Un-condense the buckets before using in furnaces, or void the liquid.').darkRed()],
        ])
    })
})