"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.PostTransformation = void 0;
const cachedEnumValues_1 = require("../../arrays/cachedEnumValues");
const ModCallbackCustom_1 = require("../../enums/ModCallbackCustom");
const playerDataStructures_1 = require("../../functions/playerDataStructures");
const DefaultMap_1 = require("../DefaultMap");
const CustomCallback_1 = require("../private/CustomCallback");
const v = {
    run: {
        // We cannot use a nested `DefaultMap` here.
        playersTransformationsMap: new DefaultMap_1.DefaultMap(() => new Map()),
    },
};
class PostTransformation extends CustomCallback_1.CustomCallback {
    v = v;
    constructor() {
        super();
        this.customCallbacksUsed = [
            [
                ModCallbackCustom_1.ModCallbackCustom.POST_PEFFECT_UPDATE_REORDERED,
                this.postPEffectUpdateReordered,
            ],
        ];
    }
    shouldFire = (fireArgs, optionalArgs) => {
        const [_player, playerForm] = fireArgs;
        const [callbackPlayerForm] = optionalArgs;
        return (callbackPlayerForm === undefined || callbackPlayerForm === playerForm);
    };
    // ModCallbackCustom.POST_PEFFECT_UPDATE_REORDERED
    postPEffectUpdateReordered = (player) => {
        const playerTransformationsMap = (0, playerDataStructures_1.defaultMapGetPlayer)(v.run.playersTransformationsMap, player);
        for (const playerForm of cachedEnumValues_1.PLAYER_FORM_VALUES) {
            const hasForm = player.HasPlayerForm(playerForm);
            let storedForm = playerTransformationsMap.get(playerForm);
            if (storedForm === undefined) {
                storedForm = false;
            }
            if (hasForm !== storedForm) {
                playerTransformationsMap.set(playerForm, hasForm);
                this.fire(player, playerForm, hasForm);
            }
        }
    };
}
exports.PostTransformation = PostTransformation;
