"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.FriendlyBounty = void 0;
const reference_data_1 = require("@firestone-hs/reference-data");
const cards_in_hand_1 = require("../../../simulation/cards-in-hand");
const utils_1 = require("../../../utils");
exports.FriendlyBounty = {
    cardIds: ["BG33_814"],
    castTavernSpell: (_spellCardId, input) => {
        var _a, _b, _c;
        const tribeCounts = new Map();
        for (const entity of input.board) {
            if (entity.health <= 0 || entity.definitelyDead)
                continue;
            const tribes = (0, utils_1.getEffectiveTribesForEntity)(entity, input.hero, input.gameState.anomalies, input.gameState.allCards);
            for (const tribe of tribes) {
                if (tribe === reference_data_1.Race.ALL) {
                    for (const bgRace of reference_data_1.ALL_BG_RACES) {
                        tribeCounts.set(bgRace, ((_a = tribeCounts.get(bgRace)) !== null && _a !== void 0 ? _a : 0) + 1);
                    }
                }
                else {
                    tribeCounts.set(tribe, ((_b = tribeCounts.get(tribe)) !== null && _b !== void 0 ? _b : 0) + 1);
                }
            }
        }
        let mostCommonTribe = null;
        let maxCount = 0;
        for (const [tribe, count] of tribeCounts) {
            if (count > maxCount) {
                maxCount = count;
                mostCommonTribe = tribe;
            }
        }
        if (mostCommonTribe == null)
            return;
        const tier = (_c = input.hero.tavernTier) !== null && _c !== void 0 ? _c : 6;
        const cardId = input.gameState.cardsData.getRandomMinionForTribe(mostCommonTribe, tier, []);
        if (cardId) {
            (0, cards_in_hand_1.addCardsInHand)(input.hero, input.board, [cardId], input.gameState);
        }
    },
};
//# sourceMappingURL=friendly-bounty.js.map