import { Debugger } from "./debug.js";

const debug = new Debugger('mythicus:mce');
debug.enabled = false;
debug.priority = 1;

/**
 * A static class that provides a simpler way to create RawMessage objects.
 *
 * @class
 */
export class Rawtext {

    static #namespace = "mythicus:"

    /**
     * Returns the rawtext object for this translation and optional variables.
     *
     * @param {String} text - Text to translate.
     * @param {String[]} [vars=[]] - Variables to substitute into the translation.
     * @returns {RawMessage} Raw message with variables.
    */
    static create(text, vars=[]) {

        // return translated text if there are no variables
        if (vars.length === 0) {
            return { rawtext: [{ translate: text }] };
        }

        const varTranslations = [];
        vars.forEach((str, index) => varTranslations[index] = str.includes(this.#namespace) || str.includes("dimension."));

        if (varTranslations.includes(true) === false) {
            return { rawtext: [{ translate: text, with: vars }] };
        }

        const varTexts = [];
        varTranslations.forEach((v, index) => {
            if (v === false) varTexts.push({ text: vars[index] });
            else varTexts.push({ translate: vars[index] });
        })

        return { rawtext: [{ translate: text, with: { rawtext: varTexts } }] };
    }

}