import { randomInt } from "node:crypto";
import { JOIN_CODE_LENGTH } from "./config.js";
const ALPHABET = "ABCDEFGHJKMNPQRSTUVWXYZ23456789";
export function newJoinCode() {
    let code = "";
    for (let i = 0; i < JOIN_CODE_LENGTH; i++) {
        code += ALPHABET[randomInt(ALPHABET.length)];
    }
    return code;
}
export function normalizeJoinCode(raw) {
    const code = raw.toUpperCase().replace(/[\s-]/g, "");
    if (code.length !== JOIN_CODE_LENGTH)
        return null;
    for (const ch of code) {
        if (!ALPHABET.includes(ch))
            return null;
    }
    return code;
}
