"use strict";
import { toUtf8Bytes, toUtf8String } from "@ethersproject/strings";
import { logger, Wordlist } from "./wordlist";
const words = "[encoded data, 14341 characters]";
let wordlist = null;
const lookup = {};
function dropDiacritic(word) {
    logger.checkNormalize();
    return toUtf8String(Array.prototype.filter.call(toUtf8Bytes(word.normalize("NFD").toLowerCase()), (c) => {
        return ((c >= 65 && c <= 90) || (c >= 97 && c <= 123));
    }));
}
function expand(word) {
    const output = [];
    Array.prototype.forEach.call(toUtf8Bytes(word), (c) => {
        // Acute accent
        if (c === 47) {
            output.push(204);
            output.push(129);
            // Grave accent
        }
        else if (c === 45) {
            output.push(204);
            output.push(128);
        }
        else {
            output.push(c);
        }
    });
    return toUtf8String(output);
}
function loadWords(lang) {
    if (wordlist != null) {
        return;
    }
    wordlist = words.replace(/([A-Z])/g, " $1").toLowerCase().substring(1).split(" ").map((w) => expand(w));
    wordlist.forEach((word, index) => {
        lookup[dropDiacritic(word)] = index;
    });
    // Verify the computed list matches the official list
    /* istanbul ignore if */
    if (Wordlist.check(lang) !== "0x51deb7ae009149dc61a6bd18a918eb7ac78d2775726c68e598b92d002519b045") {
        wordlist = null;
        throw new Error("BIP39 Wordlist for fr (French) FAILED");
    }
}
class LangFr extends Wordlist {
    constructor() {
        super("fr");
    }
    getWord(index) {
        loadWords(this);
        return wordlist[index];
    }
    getWordIndex(word) {
        loadWords(this);
        return lookup[dropDiacritic(word)];
    }
}
const langFr = new LangFr();
Wordlist.register(langFr);
export { langFr };
//# sourceMappingURL=lang-fr.js.map