import { LangsBDEFHIJPRZEnum } from '@/api/types';

import { Lang } from './Lang';
import {
    getCachedTranslationSync,
    maskText,
    queueTranslation,
} from './localizationService';

export const resolveLLText = (
    value: string | number,
    lang: LangsBDEFHIJPRZEnum,
): string => {
    const text = String(value);
    if (!text) return '';
    if (lang === 'ru') return text;

    const cached = getCachedTranslationSync(text, lang);
    if (cached !== undefined) return cached;

    queueTranslation(text, lang).catch((error) => {
        console.error('Error queueing translation:', error);
    });

    return maskText(text);
};

export const LLRender = (value: string | number | undefined): string => {
    if (!value) return '';
    return resolveLLText(value, Lang.getCurrentLang());
};
