"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.handleMinionRemovedAuraEffect = exports.removeMinionFromBoard = void 0;
const reference_data_1 = require("@firestone-hs/reference-data");
const card_interface_1 = require("../cards/card.interface");
const _card_mappings_1 = require("../cards/impl/_card-mappings");
const utils_1 = require("../utils");
const removeMinionFromBoard = (board, boardHero, index, gameState) => {
    const removedEntity = board.splice(index, 1)[0];
    (0, exports.handleMinionRemovedAuraEffect)(board, removedEntity, boardHero, gameState);
};
exports.removeMinionFromBoard = removeMinionFromBoard;
const handleMinionRemovedAuraEffect = (board, removed, boardHero, gameState, applyAttackAuras = true, applyHealthAuras = true) => {
    const onDespawnedImpl = _card_mappings_1.cardMappings[removed.cardId];
    if ((0, card_interface_1.hasOnDespawned)(onDespawnedImpl)) {
        onDespawnedImpl.onDespawned(removed, {
            hero: boardHero,
            board: board,
            gameState,
            applyAttackAuras,
            applyHealthAuras,
        });
    }
    switch (removed.cardId) {
        case "BG_EX1_507":
        case "TB_BaconUps_008":
            board
                .filter((e) => (0, utils_1.hasCorrectTribe)(e, boardHero, reference_data_1.Race.MURLOC, gameState.anomalies, gameState.allCards))
                .forEach((e) => {
                const diff = removed.cardId === "TB_BaconUps_008" ? 4 : 2;
                e.attack = Math.max(0, e.attack - diff);
            });
            break;
        case "BG_NEW1_027":
        case "TB_BaconUps_136":
            board
                .filter((e) => (0, utils_1.hasCorrectTribe)(e, boardHero, reference_data_1.Race.PIRATE, gameState.anomalies, gameState.allCards))
                .forEach((e) => {
                const diff = removed.cardId === "TB_BaconUps_136" ? 2 : 1;
                e.attack = Math.max(0, e.attack - diff);
                e.health = Math.max(1, e.health - diff);
            });
            break;
        case "BG25_043":
        case "BG25_043_G":
            board
                .filter((e) => e.divineShield)
                .forEach((e) => {
                const diff = removed.cardId === "BG25_043_G" ? 12 : 6;
                e.attack = Math.max(0, e.attack - diff);
            });
            break;
        case "BG27_030":
        case "BG27_030_G":
            board
                .filter((e) => (0, utils_1.hasCorrectTribe)(e, boardHero, reference_data_1.Race.UNDEAD, gameState.anomalies, gameState.allCards))
                .forEach((e) => {
                const diff = (removed.cardId === "BG27_030_G" ? 2 : 1) * boardHero.tavernTier;
                e.attack = Math.max(0, e.attack - diff);
            });
            break;
    }
};
exports.handleMinionRemovedAuraEffect = handleMinionRemovedAuraEffect;
//# sourceMappingURL=remove-minion-from-board.js.map