let choice1 = [
    {
        type : "skill",
        name : "Mêlée (Base)",
        diff : {
            system : {
                advances : {
                    value : 10
                }
            }
        }
    }
]
let choice2 = [
    {
        type : "skill",
        name : "Mêlée (arme d'hast)",
        diff : {
            system : {
                advances : {
                    value : 10
                }
            }
        }
    }
]

let choice =  await foundry.applications.api.DialogV2.wait({
    window : {
        title : "Choix"
    },
    content :
    `<p>
    Sélectionnez votre choix
    </p>
    <ol>
    <li>Mêlée (Base)</li>
    <li>Mêlée (arme d'hast)</li>
    </ol>
    `,
    buttons : [
        {
            label : "Base",
            callback : () => {
                return choice1;
            }
        },
        {
            label : "Arme d'hast",
            callback : () => {
                return choice2;
            }
        }
    ]
})

let updateObj = this.actor.toObject();
let items = []
for (let c of choice)
{
    let existing
    if (c.type == "skill")
    {
        existing = updateObj.items.find(i => i.name == c.name && i.type == c.type)
        if (existing && c.diff?.system?.advances?.value)
        {
            existing.system.advances.value += c.diff.system.advances.value
        }
    }

    if (!existing)
    {
        let item = await game.wfrp4e.utility.find(c.name, c.type)
        if (item)
        {
            let equip = item.system.tags.has("equippable");
            item = item.toObject()
            if (equip)
            {
                item.system.equipped.value = true;
            }
            items.push(foundry.utils.mergeObject(item, (c.diff || {})))
        }
        else
            ui.notifications.warn(`Impossible de trouver ${talent}`, {permanent : true})
    }

}
await this.actor.update(updateObj)
this.actor.createEmbeddedDocuments("Item", items);
