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

        const actorData = context.document
        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 ?? []

        const findEquipmentOnSlot = (slot, setNumber, object) => {
            return object.items.get(object.system.heldenausruestung[setNumber]?.[slot])
        }

        context.inidice = actorData.system.ini.wuerfel
        context.inivalue = actorData.system.ini.aktuell
        context.inimod = actorData.system.ini.mod

        context.aupper = Math.min((actorData.system.aup.aktuell / actorData.system.aup.max) * 100, 100)
        context.lepper = Math.min((actorData.system.lep.aktuell / actorData.system.lep.max) * 100, 100)
        context.keper = Math.min((actorData.system.kap.aktuell / actorData.system.kap.max) * 100, 100)
        context.aspper = Math.min((actorData.system.asp.aktuell / actorData.system.asp.max) * 100, 100)

        context.lepcurrent = actorData.system.lep.aktuell ?? 0
        context.aupcurrent = actorData.system.aup.aktuell ?? 0
        context.aspcurrent = actorData.system.asp.aktuell ?? 0
        context.kapcurrent = actorData.system.kap.aktuell ?? 0

        context.maxWounds = actorData.system.wunden.max ?? 3
        context.wounds = actorData.system.wunden.aktuell ?? 0
        context.woundsFilled = []
        for (let i = 1; i <= context.maxWounds; i++) {
            context.woundsFilled[i] = i <= context.wounds
        }

        context.withErschoepfung = game.settings.get("DSA_4-1", "optional_erschoepfung")
        context.ueberanstrengung = actorData.system.ueberanstrengung
        context.erschoepfung = actorData.system.erschoepfung.aktuell
        context.maxErschoepfung = actorData.system.erschoepfung.max

        context.erschoepfungFilled = []
        for (let i = 1; i <= context.maxErschoepfung; i++) {
            context.erschoepfungFilled[i] = i <= context.erschoepfung
        }


        context.effects = []
        for (let i = 0; i < actorData.appliedEffects.length; i++) {
            const item = actorData.appliedEffects[i]
            context.effects.push(item.name)
        }

        return context

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

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