import { world, system, EquipmentSlot, ItemStack } from "@minecraft/server"

// ! LORE
// ! =================================================================================
world.afterEvents.playerInventoryItemChange.subscribe(ev => {
    if (!ev.itemStack) return;
    
    const item = ev.itemStack;
    const player = ev.player;
    
    // * Smithing items update lore
    switch (item.typeId) {
        case "darkw_dotv:weapon_yin": {
            if (item.getDynamicProperty('darkw_dotv:has_registered_lore')) return
            item.setLore([`§r§4"Purity is a plauge. But it must exist to maintain balance."\n§r§4"The purest example of sacrifice. Or at least what's left of it."§r`,
                '\n§r§7On Hit:',
                ' §r§9Steals life from the victim.',
                ' §r§9Damage Dealt repairs the blade.',
                '§r§7On Crouch:',
                ' §r§9Steals holders health to charge itself up.',
                ' §r§9User will gain particles on full charge.',
                '§r§7On Use While Charged:',
                ' §r§9Blade lets off a massive explosion.',
                ' §r§9Requires at least half durability.',
                '§r§7Repairable with Netherite Ingots.',
            ]);
                item.setDynamicProperty('darkw_dotv:has_registered_lore', true)
                player.getComponent('inventory').container.setItem(ev.slot, item);
                break
            }
            case "darkw_dotv:weapon_yang": {
                if (item.getDynamicProperty('darkw_dotv:has_registered_lore')) return
                item.setLore([
                    `§r§4"Even the concept of pure evil is overritten by it's relentless vision."\n§r§4"The darkest example of selfishness. often confused with power."§r`,
                    '\n§r§7Passive Skill - Voidheart:',
                    ' §r§9When held, a number will appear on your actionbar.',
                    ' §r§9If this number is over ten and the item is used,',
                    ' §r§9The weapon will fire a beam and deal damage equal to this number.',
                    ' §r§9The holder is damaged every couple of seconds, damage taken is added to §eVoidheart§9.',
                    '§r§7On Hit:',
                    ' §r§9Steals life from the victim.',
                    ' §r§9Damage Dealt to mobs adds to §eVoidheart§9.',
                    '§r§7On Use:',
                    ' §r§9Blade fires a beam. Damage is equal to §eVoidheart§9 amount.',
                    '§r§7On Sneak:',
                    ' §r§9The holder applies §bWither V§9 to nearby entities.',
                    ' §r§9Duration is equal to your §eVoidheart§9 amount in ticks.',
                    ' §r§9(for example, 20 Voidheart is one second).',
                    '§r§7Repairable with Netherite Ingots.',
                ]);
                item.setDynamicProperty('darkw_dotv:has_registered_lore', true)
                player.getComponent('inventory').container.setItem(ev.slot, item);
                break
            }
            case "darkw_dotv:weapon_yinyang": {
                if (item.getDynamicProperty('darkw_dotv:has_registered_lore')) return
                item.setLore([
                    `§r§4"Too good to concour, Too evil to unify. Keep the balance."\n`,
                    '§r§7On Use:',
                    ' §r§9Swaps the sword mode between ANGEL, DEVIL, and LIMBO.',
                    '§r§7On Entity Hit:',
                    ' §r§9LIMBO Mode -> Hit entities souls are stored in the blade, holding them to be used in different modes.',
                    ' §r§9ANGEL Mode -> The holder gains 1% Lifesteal per 10 souls. 10% of souls are consumed on hit.',
                    ' §r§9DEVIL Mode -> Hitting entities inflicts wither, then:',
                    ' §r§9: (Not Sneaking) - Soul Damage is divided across nearby entities. (Minimum 10 Souls).',
                    ' §r§9: (Sneaking) - All Soul Damage goes into the entity attacked.',
                    '§r§7Repairable with Netherite Ingots.',
                ]);
                item.setDynamicProperty('darkw_dotv:has_registered_lore', true)
                player.getComponent('inventory').container.setItem(ev.slot, item);
            break
        }
    }
    
    // * Missmatched Lore
    if (item.getLore().length > 0) return
    // * Set Lore
    if (item.typeId.includes('alatine_') && item.getTags().includes('minecraft:is_armor')) {
        item.setLore([
            '\n§r§7Armor Stats.',
            '§r§9 +20 Armor (Full Set).',
            '§r§9 Repairable with Diamonds.',
            '§r§7Set Bonus:',
            '§r§9 Applies useful potion effects to the wearer.'
        ])
        player.getComponent('inventory').container.setItem(ev.slot, item);
    }
    if (item.typeId.includes('ageto_') && item.getTags().includes('minecraft:is_armor')) {
        item.setLore([
            '\n§r§7Armor Stats.',
            '§r§9 +20 Armor (Full Set).',
            '§r§9 Repairable with Diamonds.',
            '§r§7Set Bonus:',
            '§r§9 Void Chalk no longer uses durability.'
        ])
        player.getComponent('inventory').container.setItem(ev.slot, item);
    }
    if (item.typeId.includes('chaos_') && item.getTags().includes('minecraft:is_armor')) {
        item.setLore([
            '\n§r§7Armor Stats.',
            '§r§9 +40 Armor (Full Set).',
            '§r§9 Repairable with Diamonds.',
            '§r§7Set Bonus Skill - Power Hungry:',
            '§r§9 The wearer is always hungry, and saturation is permenantly set to zero.',
            '§r§9 The wearer gains +2 Attack Damage per piece of missing hunger.',
            '§r§9 Instead of regenerating health through eating, the wearer gains lifesteal.',
            '§r§9 : The wearer gains 2.5% lifesteal, and 5% lifesteal at zero hunger.',
        ])
        player.getComponent('inventory').container.setItem(ev.slot, item);
    }
    if (item.typeId.includes('m4rk_') && item.getTags().includes('minecraft:is_armor')) {
        item.setLore([
            '\n§r§7Armor Stats.',
            '§r§9 +38 Armor (Full Set).',
            '§r§9 Repairable with Diamonds.',
            '§r§7Passive Bonus:',
            '§r§9 The Weapon "PRY // SLASH" gains +2 Bonus Attack damage per armor piece.',
            '§r§7Set Bonus:',
            '§r§9 If the wearer is below 30% health, They gain a number of buffs:',
            '§r§9 : Speed III',
            '§r§9 : Strength VI',
            '§r§9 : Resistance II'
        ])
        player.getComponent('inventory').container.setItem(ev.slot, item);
    }
    switch (item.typeId) {
        // * Weapons
        case "darkw_dotv:weapon_deathblade": {
            item.setLore([
                '§r§7 On Hit Block (Melee attack a block):',
                '§r§9Sets off a withering explosion.',
                '§r§9Breaks if used at low durability.',
            '§r§7Repairable with Diamonds.'])
            player.getComponent('inventory').container.setItem(ev.slot, item);
            break
        }
        case "darkw_dotv:weapon_alatar": {
            item.setLore(['\n§r§7When Placed On Block:',
                ' §r§9Summons the selected Alatar rune.',
                ' §r§9! Stops working at low durability !',
                '§r§7When Used While Crouching:',
                ' §r§9Selects a new Rune',
            '§r§7Repairable with Diamonds.']);
            player.getComponent('inventory').container.setItem(ev.slot, item);
            break
        }
        case "darkw_dotv:weapon_brawlatar": {
            item.setLore([
                '§r§7Tool Bonus:',
                ' §r§9This weapon has the same strength as a Netherite Axe.',
                '§r§7On Entity Hit:',
                ' §r§9User becomes sick after enough use.',
                '§r§7When Used While Sick:',
                ' §r§9Unleashes a Fatal Poison Nova.',
            '§r§7Repairable with Diamonds.']);
            player.getComponent('inventory').container.setItem(ev.slot, item);
            break
        }
        case "darkw_dotv:weapon_eribus": {
            item.setLore([
                '\n§r§7On Hit While Sneaking:',
                ' §r§9Teleports mobs away from the holder.',
                '§r§7On Use:',
                ` §r§9Teleports the holder onto the block they're looking at.`,
            '§r§7Repairable with Diamonds.'
            ]);
            player.getComponent('inventory').container.setItem(ev.slot, item);
            break
        }
        case "darkw_dotv:weapon_puppet": {
            item.setLore(['§r§7 On Hit:',
                '§r§9Has a chance to inflict bonus damage on hit.',
            '§r§7Repairable with Diamonds.'
            ])
            player.getComponent('inventory').container.setItem(ev.slot, item);
            break
        }
        case "darkw_dotv:weapon_erian": {
            item.setLore([
                '\n§r§7On Entity Hit:',
                ' §r§9Continuously attacking a mob deals +0.5 Bonus Damage per hit.',
            '§r§7Repairable with Diamonds.'
            ]);
            player.getComponent('inventory').container.setItem(ev.slot, item);
            break
        }
        case "darkw_dotv:weapon_roxantria": {
            item.setLore([
                '\n§r§7On Use:',
                ' §r§9Turns the holder invisible for a short time.',
                '§r§7On Entity Hit:',
                ' §r§9If the holder is invisible while hitting a mob with this weapon,\n the attacked mob takes +10 Bonus Damage.',
            '§r§7Repairable with Diamonds.'
            ]);
            player.getComponent('inventory').container.setItem(ev.slot, item);
            break
        }
        case "darkw_dotv:chalk_agetomagala_boom": {
            item.setLore([
                '\n§r§7On Use On Block:',
                ' §r§9Draws a rune originated from Ageto Magala.',
                ` §r§9This rune will explode shortly after it's drawn.`,
            '§r§7Repairable with End Crystals.'
            ]);
            player.getComponent('inventory').container.setItem(ev.slot, item);
            break
        }
        case "darkw_dotv:chalk_agetomagala_darkburn": {
            item.setLore([
                '\n§r§7On Use On Block:',
                ' §r§9Draws a rune originated from Ageto Magala.',
                ` §r§9This rune will wither all entities around itself.`,
            '§r§7Repairable with End Crystals.'
            ]);
            player.getComponent('inventory').container.setItem(ev.slot, item);
            break
        }
        case "darkw_dotv:chalk_agetomagala_lightning": {
            item.setLore([
                '\n§r§7On Use On Block:',
                ' §r§9Draws a rune originated from Ageto Magala.',
                ` §r§9This rune will summon a bolt of dark lightning after being drawn.`,
            '§r§7Repairable with End Crystals.'
            ]);
            player.getComponent('inventory').container.setItem(ev.slot, item);
            break
        }
        case "darkw_dotv:charm_dubtrox": {
            item.setLore([
                '\n§r§7When placed in hotbar:',
                ' §r§9Attacking an entity has a chance to give the holder a random buff.',
                ` §r§9Effect does not stack with multiple radios.`
            ]);
            player.getComponent('inventory').container.setItem(ev.slot, item);
            break
        }
        case "darkw_dotv:weapon_prismatica": {
            item.setLore([
                '\n§r§7Passive Bonus:',
                ' §r§9When the holder is at half health, the sword will rot and',
                ` §r§9it's holder will gain a moderate speed boost.`,
            '§r§7Repairable with Diamonds.'
            ]);
            player.getComponent('inventory').container.setItem(ev.slot, item);
            break
        }
        case "darkw_dotv:weapon_roxxane": {
            item.setLore([
                '\n§r§7On Use:',
                ' §r§9The blade will launch the user into the air.',
                '§r§7On Use (Airborne):',
                ' §r§9If the blade is used again after the holder is launched,\n The user will slam into the ground, damaging nearby mobs.',
            '§r§7Repairable with Diamonds.'
            ]);
            player.getComponent('inventory').container.setItem(ev.slot, item);
            break
        }
        case "darkw_dotv:bow_roxxane": {
            item.setLore([
                '\n§r§7On Full Charge:',
                ' §r§9Rapidly fires arrows from the users inventory.',
                '§r§7Notes:',
                ' §r§9This product does not support tipped arrows.',
            '§r§7Repairable with Diamonds.'
            ]);
            player.getComponent('inventory').container.setItem(ev.slot, item);
            break
        }
        case "darkw_dotv:weapon_faevia": {
            item.setLore([
                '\n§r§7On Use:',
                ' §r§9The holder will launch in the direction they are looking.',
            '§r§7Repairable with Diamonds.'
            ]);
            player.getComponent('inventory').container.setItem(ev.slot, item);
            break
        }
        case "darkw_dotv:charm_triox": {
            item.setLore([
                '\n§r§7On Crouch:',
                ' §r§9Crouching will cause you to block, damaging entities that attack you.',
                ' §r§9Wearer will also gain Resistance if the gauntlets are not on cooldown.',
                '§r§7Dev Note:',
                ` §r§9Item is known to defy Minecraft's laws of rendering while equipped\n in the off hand and holding another item in the main hand.\n It's just chill like that I guess.`,
            ]);
            player.getComponent('inventory').container.setItem(ev.slot, item);
            break
        }
        case "darkw_dotv:weapon_legatus": {
            item.setLore([
                '\n§r§7On Use:',
                ' §r§9The sword will summon a rune on the block you are looking at.',
            '§r§7Repairable with Diamonds.'
            ]);
            player.getComponent('inventory').container.setItem(ev.slot, item);
            break
        }
        case "darkw_dotv:charm_legatus": {
            item.setLore([
                '\n§r§7On Crouch:',
                ' §r§9Holding a crouch will cause the holder to explode and damage nearby entities.',
            ]);
            player.getComponent('inventory').container.setItem(ev.slot, item);
            break
        }
        case "darkw_dotv:kunai_puppet": {
            item.setLore([
                '§r§4"A dark seed planted from the beginning."',
                '\n§r§7On Use:',
                ' §r§9Throws a piece of Kunai directly ahead of you.',
                ' §r§9Hit entities damage mobs around them.',
                ' §r§9Recovers durability on mob kill while in the inventory.',
            ]);
            player.getComponent('inventory').container.setItem(ev.slot, item);
            break
        }
        case "darkw_dotv:totem_m4rk": {
            item.setLore([
                '\n§r§9If the holder §btakes Void Damage while below half health§9, they\nare teleported to the last block they stood on.',
            ]);
            player.getComponent('inventory').container.setItem(ev.slot, item);
            break
        }
        case "darkw_dotv:weapon_m4rk": {
            item.setLore(['§r§7On Use:\n  §9Currently selected attack is used.\n§r§7When Used while crouching:\n  §9Selects a new attack.\n  §9Actionbar will tell you the newly selected attack.',
            '§r§7Repairable with Diamonds.']);
            player.getComponent('inventory').container.setItem(ev.slot, item);
            break
        }
        case "darkw_dotv:tmp_alatine": {
            item.setLore(['§r§7Smithing Template\n',
                '§r§7Applies to:\n§9 Diamond Armor',
                '§r§7Ingredients:\n §9Netherite Ingot']);
            player.getComponent('inventory').container.setItem(ev.slot, item);
            break
        }
        case "darkw_dotv:tmp_chaos": {
            item.setLore(['§r§7Smithing Template\n',
                '§r§7Applies to:\n§9 Diamond Armor',
                '§r§7Ingredients:\n §9Netherite Ingot']);
            player.getComponent('inventory').container.setItem(ev.slot, item);
            break
        }
        case "darkw_dotv:tmp_ageto": {
            item.setLore(['§r§7Smithing Template\n',
                '§r§7Applies to:\n§9 Diamond Armor',
                '§r§7Ingredients:\n §9Netherite Ingot']);
            player.getComponent('inventory').container.setItem(ev.slot, item);
            break
        }
        case "darkw_dotv:tmp_mark": {
            item.setLore([
                '§r§7Smithing Template\n',
                '§r§7Applies to:\n§9 Diamond Armor',
                '§r§7Ingredients:\n §9Netherite Ingot']);
            player.getComponent('inventory').container.setItem(ev.slot, item);
            break
        }
        case "darkw_dotv:weapon_agetomagala": {
            item.setLore([
                '§r§7On Entity Hit:',
                ' §r§9The sword has a 14% chance of letting of an explosion.',
            '§r§7Repairable with End Crystals.'
            ]);
            player.getComponent('inventory').container.setItem(ev.slot, item);
            break
        }
        case "darkw_dotv:tmp_terr_a": {
            item.setLore([
                '§r§7Smithing Template\n',
                '§r§7Applies to:\n§b Carcer',
                '§r§9 : (Dropped by Extorris-Poeta)',
                '§r§7Ingredients:\n §9Netherite Ingot'
            ]);
            player.getComponent('inventory').container.setItem(ev.slot, item);
            break
        }
        case "darkw_dotv:tmp_terr_b": {
            item.setLore([
                '§r§7Smithing Template\n',
                '§r§7Applies to:\n§b Crystalizer',
                '§r§9 : (Dropped by Ageto-Magala)',
                '§r§7Ingredients:\n §9Netherite Ingot'
            ]);
            player.getComponent('inventory').container.setItem(ev.slot, item);
            break
        }
        case "darkw_dotv:tmp_terr_whole": {
            item.setLore([
                '§r§7Smithing Template\n',
                '§r§7Applies to:\n§d PRY // SLASH',
                '§r§9 : (Dropped by M4RK, The Dark Creator)',
                '§r§7Ingredients:\n §9Netherite Ingot'
            ]);
            player.getComponent('inventory').container.setItem(ev.slot, item);
            break
        }
        case "darkw_dotv:tame_leg": {
            item.setLore([
                '§r§7A broken sword lost to time.', 
                '§r §9Can be used to tame Legatus'
            ])
            player.getComponent('inventory').container.setItem(ev.slot, item);
            break
        }
    }
})