// priority: 0

ItemEvents.tooltip(event => {
    let disabledItems = ["createaddition:rolling_mill", "createaddition:connector", "createaddition:small_light_connector", "createaddition:large_connector", "createaddition:redstone_relay", "createaddition:modular_accumulator", "createaddition:electrum_ingot", "createaddition:electrum_nugget", "createaddition:electrum_sheet", "createaddition:electrum_wire", "createaddition:electrum_rod", "createaddition:electrum_spool", "createaddition:seed_oil_bucket", "createaddition:bioethanol_bucket", "createaddition:electrum_amulet"]
    disabledItems.forEach(i => {
        event.addAdvanced([`${i}`], (item, advanced, text) => {
            text.add(1, [
                Text.of("This feature is disabled").red()
            ])
        })
    })

    event.addAdvanced(['kubejs:creative_hatchet'], (item, advanced, text) => {
        text.add(1, [
            Text.of("You have been blessed by the grace").gray()
        ])
        text.add(2, [
            Text.of('of Artemis, the Diety of Harvest').gray()
        ])
        text.add(3, [
            Text.of('')
        ])
    })

    event.addAdvanced(['kubejs:unbreaking_core'], (item, advanced, text) => {
        text.add(1, [
            Text.of('')
        ])
        text.add(2, [
            Text.of('When Combined With Any Tool or Armour').gray()
        ])
        text.add(3, [
            Text.of(' Applies Unbreakable').blue()
        ])
    })

    let almalgamation = (item_id, tooltip, colour) => {
        event.addAdvanced([`garnished_additions:${item_id}`], (item, advanced, text) => {
            text.add(1, [
                Text.of([`${colour ? colour : '§f'}` + tooltip])
            ])
        })
    }

    event.addAdvanced(['garnished_additions:chocolate_nut_mix'], (item, advanced, text) => {
        text.add(1, [
            Text.of('Chocolate Glazed').color(0xB1543E)
        ])
    })

    event.addAdvanced(['garnished_additions:honeyed_nut_mix'], (item, advanced, text) => {
        text.add(1, [
            Text.of('Honeyed').color(0xEE890F)
        ])
    })

    almalgamation('garnished_nut_mix', 'Garnished', '§7')
    almalgamation('sweetened_nut_mix', 'Sweetened', '§b')
    almalgamation('cinder_flour_nut_mix', 'Cinder Flour', '§c')
    almalgamation('melted_cinder_flour_nut_mix', 'Melted Cinder Flour', '§c')

    let rewardkit = (chapter, summary) => {
        let i = chapter.toLowerCase()
        event.addAdvanced([`kubejs:${chapter == 'Sturdy' ? 'train' : i}_rewardkit`], (item, advanced, text) => {
            text.add(1, [
                Text.of(`§5${summary}`)
            ])
            text.add(2, [
                Text.of('')
            ])
            text.add(3, [
                Text.of(`§6Obtained from chapters relating to ${chapter} Machinery`)
            ])
        })
    }

    rewardkit('Andesite', 'Your first steps as an engineer deserve some praise!')
    rewardkit('Lead', 'Efficiency is best served across long distances!')
    rewardkit('Copper', `Congrats on your next breakthrough, here's a reward!`)
    rewardkit('Brass', `With such precision, you're bound to develop new mechanics!`)
    rewardkit('Sturdy', 'Sturdy is the mind, they say.')
    rewardkit('Invar', 'Your machines are about to get so much more compact!')
    rewardkit('Silicon', 'Storage problems? Never heard of them!')
    rewardkit('Ender', 'Time for a Wireless Solution!')

    let mechanism_assembly = (item_id, machine_chapter) => {
        event.add(`${item_id}`, [`§6Main Assembly: ${machine_chapter}`])
    }

    mechanism_assembly('kubejs:wooden_mechanism', 'Andesite Machines')
    mechanism_assembly('kubejs:andesite_mechanism', 'Andesite Machines')
    mechanism_assembly('kubejs:andesite_machine', 'Andesite Machines')
    mechanism_assembly('kubejs:andesite_template', 'Andesite Machines')
    mechanism_assembly('create:andesite_casing', 'Andesite Machines')
    mechanism_assembly('kubejs:lead_mechanism', 'Lead Machines')
    mechanism_assembly('kubejs:lead_machine', 'Lead Machines')
    mechanism_assembly('kubejs:lead_template', 'Lead Machines')
    mechanism_assembly('kubejs:lead_casing', 'Lead Machines')
    mechanism_assembly('kubejs:copper_mechanism', 'Copper Machines')
    mechanism_assembly('kubejs:copper_machine', 'Copper Machines')
    mechanism_assembly('kubejs:copper_template', 'Copper Machines')
    mechanism_assembly('create:copper_casing', 'Copper Machines')
    mechanism_assembly('create:precision_mechanism', 'Brass Machines')
    mechanism_assembly('kubejs:brass_machine', 'Brass Machines')
    mechanism_assembly('kubejs:brass_template', 'Brass Machines')
    mechanism_assembly('create:brass_casing', 'Brass Machines')
    mechanism_assembly('kubejs:train_mechanism', 'Sturdy Machines')
    mechanism_assembly('kubejs:train_machine', 'Sturdy Machines')
    mechanism_assembly('kubejs:train_template', 'Sturdy Machines')
    mechanism_assembly('create:railway_casing', 'Sturdy Machines')
    mechanism_assembly('kubejs:invar_mechanism', 'Invar Machines')
    mechanism_assembly('kubejs:invar_machine', 'Invar Machines')
    mechanism_assembly('kubejs:invar_template', 'Invar Machines')
    mechanism_assembly('thermal:machine_frame', 'Invar Machines')
    mechanism_assembly('kubejs:silicon_mechanism', 'Silicon Machines')
    mechanism_assembly('kubejs:silicon_machine', 'Silicon Machines')
    mechanism_assembly('kubejs:silicon_template', 'Silicon Machines')
    mechanism_assembly('kubejs:silicon_casing', 'Silicon Machines')
    mechanism_assembly('kubejs:ender_mechanism', 'Ender Machines')
    mechanism_assembly('kubejs:ender_machine', 'Ender Machines')
    mechanism_assembly('kubejs:ender_template', 'Ender Machines')
    mechanism_assembly('kubejs:ender_casing', 'Ender Machines')

    event.addAdvanced(['kubejs:hellish_essence_bucket'], (item, advanced, text) => {
        text.add(1, [
            Text.of("Can only fuel Blaze Burners that have Straws").gray()
        ])
        text.add(2, [
            Text.of("")
        ])
        text.add(3, [
            Text.of("Bucket is consumed when using on a Blaze Burner").gray()
        ])
    })

    let template = (chapter, mechanism) => {
        let i = chapter.toLowerCase()
        event.addAdvanced([`kubejs:${i}_template`], (item, advanced, text) => {
            text.add(1, [
                Text.of(`${chapter == 'Train' ? 'Sturdy' : chapter} Machine Upgrade`).gray()
            ])
            text.add(2, [
                Text.of('')
            ])
            text.add(3, [
                Text.of('Applies to:').gray()
            ])
            text.add(4, [
                Text.of(` ${chapter} Mechanical Components`).blue()
            ])
            text.add(5, [
                Text.of("Ingredients:").gray()
            ])
            text.add(6, [
                Text.of(` ${mechanism} Mechanism`).blue()
            ])
        })
    }

    template('Andesite', 'Rudimentary')
    template('Lead', 'Logistic')
    template('Copper', 'Paradigm')
    template('Brass', 'Precision')
    template('Train', 'Passage')
    template('Invar', 'Intricate')
    template('Silicon', 'Progressive')
    template('Ender', 'Awakened')

    event.addAdvanced(['kubejs:nutium_template'], (item, advanced, text) => {
        text.add(1, [
            Text.of('Nutium Upgrade').gray()
        ])
        text.add(2, [
            Text.of('')
        ])
        text.add(3, [
            Text.of('Applies to:').gray()
        ])
        text.add(4, [
            Text.of('Netherite Equipment').blue()
        ])
        text.add(5, [
            Text.of("Ingredients:").gray()
        ])
        text.add(6, [
            Text.of('Nutium Ingot').blue()
        ])
    })

    event.addAdvanced(['garnished:anniversary_cake_slice'], (item, advanced, text) => {
        text.remove(1)
    })
    event.addAdvanced(['garnished:pecan_pie_slice'], (item, advanced, text) => {
        text.remove(1)
    })
    event.addAdvanced(['garnished:phantom_burger'], (item, advanced, text) => {
        text.remove(1)
    })
    event.addAdvanced(['garnished:phantom_beef_patty'], (item, advanced, text) => {
        text.remove(1)
    })
    event.addAdvanced(['garnished:glow_ink_roll'], (item, advanced, text) => {
        text.remove(1)
    })
    event.addAdvanced(['garnished:glow_ink_roll_slice'], (item, advanced, text) => {
        text.remove(1)
    })
})

ClientEvents.lang("en_us", e => {
    e.renameItem('thermal:machine_frame', 'Invar Casing')
    // e.renameItem('ae2:controller', 'Silicon Casing')
    // e.renameItem('create:brass_hand', 'Gold Hand')

    e.renameItem('sophisticatedbackpacks:backpack', 'Andesite Backpack')
    e.renameItem('sophisticatedbackpacks:copper_backpack', 'Copper Backpack')
    e.renameItem('sophisticatedbackpacks:iron_backpack', 'Brass Backpack')
    e.renameItem('sophisticatedbackpacks:gold_backpack', 'Sturdy Backpack')
    e.renameItem('sophisticatedbackpacks:diamond_backpack', 'Invar Backpack')
    e.renameItem('sophisticatedbackpacks:netherite_backpack', 'Silicon Backpack')

    e.renameItem('create:precision_mechanism', '§ePrecision Mechanism')

    e.renameItem('garnished_additions:garnished_nut_mix', 'Nut Amalgamation')
    e.renameItem('garnished_additions:sweetened_nut_mix', 'Nut Amalgamation')
    e.renameItem('garnished_additions:chocolate_nut_mix', 'Nut Amalgamation')
    e.renameItem('garnished_additions:honeyed_nut_mix', 'Nut Amalgamation')
    e.renameItem('garnished_additions:cinder_flour_nut_mix', 'Nut Amalgamation')
    e.renameItem('garnished_additions:melted_cinder_flour_nut_mix', 'Nut Amalgamation')
    
    e.renameItem('minecraft:scute', 'Turtle Scute')

    e.renameItem('alexscaves:scarlet_neodymium_ingot', 'Scarlet Neodymium Alloy')
    e.renameItem('alexscaves:azure_neodymium_ingot', 'Azure Neodymium Alloy')
})

JEIEvents.addItems(event => {
    event.add(Item.of('create:chromatic_compound'))
    event.add(Item.of('create:shadow_steel'))
    event.add(Item.of('create:refined_radiance'))
})

JEIEvents.information(event => {
    event.addItem(
        'create:shadow_steel',
        [Text.of(`Drop a Chromatic Compound into the void and watch Shadow Steel float back up.`)],
    )
    event.addItem(
        'create:refined_radiance',
        [Text.of(`Throw a Chromatic Compound into a Beacon beam and watch Refined Radiance float upward.`)],
    )
})

