/** Tournament-standard battle sizes by points ceiling (10th ed). */
const BATTLE_SIZES = [
    { upper: 500, label: "Combat Patrol (500 Point limit)" },
    { upper: 1000, label: "Incursion (1000 Point limit)" },
    { upper: 2000, label: "Strike Force (2000 Point limit)" },
    { upper: 3000, label: "Onslaught (3000 Point limit)" },
];
/**
 * Synthesize a {@link ParsedRoster.battle_size_raw} from a points limit. The
 * wtc/simple formats don't carry the battle-size label explicitly — they only
 * report the total army points — so we map the limit to its standard label
 * (the same one {@link mapBattleSize} expects).
 */
export function inferBattleSizeRaw(limit) {
    if (limit === null)
        return null;
    for (const { upper, label } of BATTLE_SIZES) {
        if (limit <= upper)
            return label;
    }
    return BATTLE_SIZES[BATTLE_SIZES.length - 1].label; // beyond Onslaught: cap at Onslaught
}
const NX_PREFIX = /^(\d+)x\s+(.+)$/;
const INLINE_PTS = /^(.+?)\s*\[\s*(\d+)\s*pts?\s*\]\s*$/i;
const CHARACTER_SUFFIX = " Character";
const WARLORD_MARKER = "Warlord";
/**
 * Classify each token in a comma-separated wargear list. Strips the markers
 * that aren't real wargear — `Warlord`, the detachment "<Name> Character"
 * keyword, and the inline `Name [N pts]` enhancement (simple format) — and
 * collects everything else as {@link ParsedWargear} with optional `Nx` count.
 *
 * Tokens are pre-split: pass `["Armoured feet", "2x War Dog autocannon", ...]`.
 */
export function classifyWargearList(tokens) {
    const wargear = [];
    let is_warlord = false;
    let is_character = false;
    let enhancement_raw_name = null;
    let enhancement_points = null;
    for (const raw of tokens) {
        const token = raw.trim();
        if (!token)
            continue;
        if (token === WARLORD_MARKER) {
            is_warlord = true;
            continue;
        }
        if (token.endsWith(CHARACTER_SUFFIX)) {
            is_character = true;
            continue;
        }
        // Simple format inlines the enhancement as `Name [15 pts]`.
        const pts = INLINE_PTS.exec(token);
        if (pts) {
            if (enhancement_raw_name === null) {
                enhancement_raw_name = pts[1].trim();
                enhancement_points = Number.parseInt(pts[2], 10);
            }
            continue;
        }
        const nx = NX_PREFIX.exec(token);
        if (nx) {
            const count = Number.parseInt(nx[1], 10);
            wargear.push({ raw_name: nx[2].trim(), count: count > 0 ? count : 1 });
        }
        else {
            wargear.push({ raw_name: token, count: 1 });
        }
    }
    return { wargear, is_warlord, is_character, enhancement_raw_name, enhancement_points };
}
/**
 * Split a wargear list on top-level commas. (No nested parentheses with commas
 * are produced by NewRecruit, so a plain split is enough; the helper keeps
 * intent explicit for future format quirks.)
 */
export function splitWargearList(text) {
    return text
        .split(",")
        .map((s) => s.trim())
        .filter((s) => s.length > 0);
}
/** Strip a trailing parenthetical (e.g. "Houndpack Lance (Marked Prey)" → "Houndpack Lance"). */
export function stripParenthetical(name) {
    const idx = name.indexOf("(");
    return idx >= 0 ? name.slice(0, idx).trim() : name.trim();
}
/** Pull the primary faction out of a "Super - Sub" keyword, e.g.
 * "Chaos - Chaos Knights" → "Chaos Knights". Shared by the wtc and GW headers. */
export function factionFromKeyword(value) {
    const parts = value.split(" - ");
    return (parts[parts.length - 1] ?? value).trim();
}
/** Parse a `(\d+) pts` or `[\d+ pts]` suffix from a unit header line. */
export function pointsFrom(token) {
    const m = /\(\s*(\d+)\s*pts?\s*\)|\[\s*(\d+)\s*pts?\s*\]/i.exec(token);
    if (!m)
        return null;
    return Number.parseInt(m[1] ?? m[2], 10);
}
//# sourceMappingURL=newrecruit-text.js.map