"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.groupLeapfroggerDeathrattles = void 0;
const MAX_LEAPFROGGER_GROUPS = 12;
const groupLeapfroggerDeathrattles = (rememberedDeathrattles) => {
    const candidates = rememberedDeathrattles
        .filter((deathrattle) => { var _a; return (_a = deathrattle.cardId) === null || _a === void 0 ? void 0 : _a.startsWith("BG21_000"); })
        .map((d) => {
        if (d.cardId.endsWith('e')) {
            return { ...d, cardId: d.cardId.slice(0, -1) };
        }
        return d;
    });
    const normalGroups = groupDeathrattles(candidates.filter((d) => d.cardId === "BG21_000"));
    const goldenGroups = groupDeathrattles(candidates.filter((d) => d.cardId === "BG21_000_G"));
    return [...normalGroups, ...goldenGroups];
};
exports.groupLeapfroggerDeathrattles = groupLeapfroggerDeathrattles;
const groupDeathrattles = (candidates) => {
    const totalRepeats = candidates.reduce((acc, next) => acc + next.repeats, 0);
    if (totalRepeats <= MAX_LEAPFROGGER_GROUPS) {
        return candidates;
    }
    const result = [];
    const repeatsPerGroup = Math.ceil(totalRepeats / MAX_LEAPFROGGER_GROUPS);
    let repeatsLeft = totalRepeats;
    for (let i = 0; i < MAX_LEAPFROGGER_GROUPS; i++) {
        const groupRepeats = Math.min(repeatsPerGroup, repeatsLeft);
        result.push({ ...candidates[0], repeats: groupRepeats });
        repeatsLeft -= groupRepeats;
    }
    return result;
};
//# sourceMappingURL=remembered-deathrattle.js.map