export default {
    _prepareContext: (context, object) => {

        const actorData = context.document
        context.spells = []
        context.system = actorData.system
        context.flags = actorData.flags
        context.derived = context.document.system
        context.originalName = actorData.name
        context.name = context.derived.name ?? actorData.name
        context.effects = actorData.effects ?? []

        context.isGM = game.user.isGM
        context.effects = []

        for (let i = 0; i < actorData.appliedEffects.length; i++) {
            const item = actorData.appliedEffects[i]
            const conditions = []

            item.changes.forEach(change => {
                if (change.key.indexOf("wunden") === -1) {
                    const key = change.key
                        .replace(/system\./g, "")
                        .replace(/\.mod/g, "")
                        .replace(/attribute./g, "")
                        .replace(/.links/g, "(Links)")
                        .replace(/.rechts/g, "(Rechts)")
                    const value = Number(change.value) > 0 ? "+" + change.value : change.value
                    conditions.push(
                        `${key}${value}`
                    )
                }
            })

            context.effects.push({
                name: item.parent.name,
                conditions: conditions.join(" "),
                id: item.parent._id,
                actor: actorData._id
            });

        }

        return context
    },
    _onRender: (context, options) => {

    },
    _getTabConfig: (group) => {
        group.tabs.push({id: "effects", group: "sheet", label: "Effekte"})
    },
    template: `systems/DSA_4-1/templates/actor/character/tab-effects.hbs`
}