'use strict';

const helpers = require('./helpers-d38772ff.js');

const en = {
	"credit-card.cardholder": "cardholder",
	"credit-card.fullname": "full name",
	"credit-card.expires": "expires",
	"datatable.search": "Search",
	"datatable.apply": "Apply filters",
	"datatable.pagination": "Showing *:count* of *:total* total item:total(s).",
	"datatable.show-more": "show more items",
	"datatable.no-results": "no results found",
	"datatable.empty": "there are no items to display",
	"datatable.select-filter": "Select a filter",
	"datatable.filter-by": "Filter by",
	"datatable.available-filters": "*:n* available filter:n(s)",
	"datatable.active-filters": "*:n* active filter:n(s)",
	"datatable.clear-filters": "Clear all filters",
	"datatable.condition": "Condition",
	"datatable.select-condition": "Select condition",
	"datatable.operator": "Operators",
	"datatable.range": "Range",
	"datatable.gt": "Greater than",
	"datatable.egt": "Greater and equal than",
	"datatable.lt": "Lower than",
	"datatable.elt": "Lower and equal than",
	"datatable.e": "Equal than",
	"datatable.ne": "Not equal than",
	"datatable.btw": "Between",
	"datatable.nbtw": "Not between",
	"datatable.contains": "Contains",
	"datatable.value": "Value",
	"datatable.to": "To",
	"datatable.from": "From",
	"datatable.date": "Date",
	"aria.close": "Close",
	"fields.autocomplete-results": "Showing :count suggestion:count(s)",
	"fields.count-more": "and :count more ...",
	"fields.list-empty": "List is empty.",
	"fields.max-options": "Maximum of :max option:max(s) selected. First remove a selected option to select another.",
	"fields.no-results": "No elements found. Consider changing the search query.",
	"fields.show-results": "Showing :count result:count(s)",
	"fields.select-option": "Select an option",
	"fields.press-enter-tag": "Press enter to create a tag",
	"fields.add-tag": "Add a tag",
	"fields.cropper.upload": "*Choose a file* or drag it here",
	"fields.cropper.sizes": "Select size",
	"fields.input.color": "Pick a color",
	"fields.paste-here": "Tap *here* to paste from clipboard",
	"fields.upload-file": "Choose a file",
	"fields.validation.bad-input": "This field is invalid",
	"fields.validation.pattern-mismatch": "The value is not valid",
	"fields.validation.range-overflow": "The value must be a number less than :max",
	"fields.validation.range-underflow": "The value should be a number greater than :min",
	"fields.validation.step-mismatch": "The value is not valid",
	"fields.validation.too-long": "This field must be at most :max character:max(s)",
	"fields.validation.too-short": "This field must be at least :min character:min(s)",
	"fields.validation.type-mismatch": "The value is not valid",
	"fields.validation.value-missing": "This field is required",
	"fields.validation.file-too-large": "The file size must be less than :size",
	"fields.validation.invalid-image-type": "The accepted file types for this field do not include images",
	"stepper.back": "Back",
	"stepper.next": "Next",
	"stepper.finish": "Finish",
	"alert.success": "That's great!",
	"alert.danger": "Oops!",
	"alert.confirm": "Confirmation",
	"alert.exception": "Something's wrong",
	"alert.error": "Something's wrong",
	"alert.invalid": "Invalid fields",
	"alert.missing": "Missing",
	"alert.payment": "Payment declined",
	"alert.unknown": "Unknown error",
	"alert.failure": "Failure",
	"alert.no-result": "No results",
	"alert.forbidden": "Access denied",
	"alert.close": "Close",
	"alert.confirm-yes": "Yes",
	"alert.confirm-no": "No",
	"cropper.zoom_in": "Zoom in",
	"cropper.zoom_out": "Zoom out",
	"cropper.rotate_left": "Rotate left",
	"cropper.rotate_right": "Rotate right",
	"cropper.center": "Center",
	"cropper.cancel": "Cancel",
	"cropper.confirm": "Confirm",
	"cropper.continue": "Continue",
	"cropper.preview_confirm_message": "Do you want to use this image?",
	"gallery.gallery": "Gallery",
	"gallery.generate": "Generate",
	"gallery.url": "From URL",
	"gallery.youtube": "Youtube",
	"gallery.select": "Select",
	"gallery.back": "Back",
	"gallery.view-more": "View more",
	"gallery.gallery-results": "*:length element:length(s)* of *:total* are displayed in total",
	"gallery.generate-placeholder": "Enter a short prompt of what you need...",
	"gallery.generated-images": "Generated Images",
	"gallery.suggested-images": "Similar images generated by other people",
	"gallery.search-placeholder": "What video do you want to search for?",
	"gallery.search-results": "*:total search results* found",
	"gallery.search-title": "Search results"
};

const EN = /*#__PURE__*/Object.freeze({
	__proto__: null,
	'default': en
});

const es = {
	"credit-card.cardholder": "titular de la tarjeta",
	"credit-card.fullname": "nombre completo",
	"credit-card.expires": "expira",
	"datatable.search": "Buscar",
	"datatable.apply": "Aplicar filtros",
	"datatable.pagination": "Mostrando *:count* de *:total* elemento:total(s) en total.",
	"datatable.show-more": "mostrar más elementos",
	"datatable.no-results": "no se encontraron resultados",
	"datatable.empty": "no hay elementos para mostrar",
	"datatable.select-filter": "Seleccione un filtro",
	"datatable.filter-by": "Filtrar por",
	"datatable.available-filters": "*:n* filtro:n(s) disponible:n(s)",
	"datatable.active-filters": "*:n* filtro:n(s) activo:n(s)",
	"datatable.clear-filters": "Limpiar todos los filtros",
	"datatable.condition": "Condición",
	"datatable.select-condition": "Seleccione la condición",
	"datatable.operator": "Operadores",
	"datatable.range": "Rango",
	"datatable.gt": "Mayor a",
	"datatable.egt": "Mayor o igual a",
	"datatable.lt": "Menor a",
	"datatable.elt": "Menor o igual a",
	"datatable.e": "Igual a",
	"datatable.ne": "Diferente a",
	"datatable.btw": "Entre los valores",
	"datatable.nbtw": "No entre los valores",
	"datatable.contains": "Contiene",
	"datatable.value": "Valor",
	"datatable.to": "Hasta",
	"datatable.from": "Desde",
	"datatable.date": "Fecha",
	"aria.close": "Cerrar",
	"fields.autocomplete-results": "Mostrando :count recomendaci:count(ón|ones)",
	"fields.count-more": "y :count más ...",
	"fields.list-empty": "La lista está vacía.",
	"fields.max-options": "Máximo de :max opción:max(es) seleccionada:max(s). Primero elimine una opción seleccionada para seleccionar otra.",
	"fields.no-results": "No se encontraron elementos. Considere cambiar la consulta de búsqueda.",
	"fields.show-results": "Mostrando :count resultado:count(s)",
	"fields.select-option": "Seleccione una opción",
	"fields.press-enter-tag": "Presiona enter para crear una etiqueta",
	"fields.add-tag": "Agrega una etiqueta",
	"fields.cropper.upload": "*Elija un archivo* o arrástrelo aquí",
	"fields.cropper.sizes": "Selecciona el tamaño",
	"fields.input.color": "Elige un color",
	"fields.paste-here": "Toca *aquí* para pegar desde el portapapeles",
	"fields.upload-file": "Elija un archivo",
	"fields.validation.bad-input": "Este campo no es válido",
	"fields.validation.pattern-mismatch": "El valor no es válido",
	"fields.validation.range-overflow": "El valor debe ser un número menor que :max",
	"fields.validation.range-underflow": "El valor debe ser un número mayor que :min",
	"fields.validation.step-mismatch": "El valor no es válido",
	"fields.validation.too-long": "Este campo debe tener como máximo :max caracter:max(es)",
	"fields.validation.too-short": "Este campo debe tener al menos :min caracter:min(es)",
	"fields.validation.type-mismatch": "El valor no es válido",
	"fields.validation.value-missing": "Este campo es obligatorio",
	"fields.validation.file-too-large": "El tamaño del archivo debe ser menor que :size",
	"fields.validation.invalid-image-type": "Los tipos de archivo aceptados para este campo no incluyen imágenes",
	"stepper.back": "Regresar",
	"stepper.next": "Siguiente",
	"stepper.finish": "Finalizar",
	"alert.success": "¡Qué bien!",
	"alert.danger": "¡Ups!",
	"alert.confirm": "Confirmación",
	"alert.exception": "Algo anda mal",
	"alert.error": "Algo anda mal",
	"alert.invalid": "Campos inválidos",
	"alert.missing": "Falta algo",
	"alert.payment": "Pago declinado",
	"alert.unknown": "Error desconocido",
	"alert.failure": "Algo falló",
	"alert.no-result": "Sin resultados",
	"alert.forbidden": "Acceso denegado",
	"alert.close": "Cerrar",
	"alert.confirm-yes": "Sí",
	"alert.confirm-no": "No",
	"cropper.zoom_in": "Acercar",
	"cropper.zoom_out": "Alejar",
	"cropper.rotate_left": "Girar a la izquierda",
	"cropper.rotate_right": "Girar a la derecha",
	"cropper.center": "Centrar",
	"cropper.cancel": "Cancelar",
	"cropper.confirm": "Confirmar",
	"cropper.continue": "Continuar",
	"cropper.preview_confirm_message": "¿Deseas usar esta imagen?",
	"gallery.gallery": "Galería",
	"gallery.generate": "Generar",
	"gallery.url": "Desde URL",
	"gallery.youtube": "YouTube",
	"gallery.select": "Seleccionar",
	"gallery.back": "Regresar",
	"gallery.view-more": "Ver más",
	"gallery.gallery-results": "Se muestran *:length elemento:length(s)* de *:total* en total",
	"gallery.generate-placeholder": "Ingresa una corta descripción de lo que necesitas ...",
	"gallery.generated-images": "Imagenes Generadas",
	"gallery.suggested-images": "Imagenes similares generadas por otras personas",
	"gallery.search-placeholder": "Que video deseas buscar?",
	"gallery.search-results": "Se encontraron *:total resultado:total(s)* de la busqueda",
	"gallery.search-title": "Resultados de busqueda"
};

const ES = /*#__PURE__*/Object.freeze({
	__proto__: null,
	'default': es
});

const strings = {
    en: EN,
    es: ES,
};
class LangService {
    /**
     * Init service
     *
     * @param _ Locale strings collection
     */
    constructor(_ = {}) {
        this._ = _;
        const locale = helpers.getLang();
        this.set(locale);
        this._ = strings[LangService.locale].default;
        const observer = new MutationObserver(function (mutations) {
            mutations.forEach((mutation) => {
                if (mutation.type === "attributes" && locale != LangService.locale) {
                    LangService.locale = locale;
                    if (strings && Object.keys(strings).includes(locale)) {
                        this._ = strings[LangService.locale].default;
                    }
                }
            });
        });
        observer.observe(document.querySelector('html'), { attributes: true });
    }
    /**
     * Set global locale
     *
     * @param locale
     */
    set(locale) {
        if (['en', 'es'].includes(locale)) {
            LangService.locale = locale;
            document.querySelector('html').setAttribute('lang', locale);
        }
        this._ = strings[LangService.locale].default;
    }
    /**
     * Get translate string by key identifier
     *
     * @param key
     * @param replace
     * @returns
     */
    get(key, replace = {}) {
        try {
            let text = this._[key];
            if (!text)
                return key;
            for (const find of Object.keys(replace)) {
                const value = replace[find];
                const regex = new RegExp(`:${find}(\\(([^)]*)\\))?`, 'g');
                text = text.replace(regex, (_parens, parens, inside) => {
                    if (!parens) {
                        return value;
                    }
                    if (inside.includes('|')) {
                        const [singular, plural] = inside.split('|');
                        return value == 1 ? singular : plural;
                    }
                    else {
                        return value == 1 ? '' : inside;
                    }
                });
            }
            return text;
        }
        catch (error) {
            console.warn('LangService.get error:', error);
            return key;
        }
    }
    /**
     * Create service
     *
     * @returns
     */
    static create() {
        const instance = new LangService();
        return Object.assign((key, replace) => instance.get(key, replace), {
            set: (locale) => instance.set(locale),
            get: (key, replace) => instance.get(key, replace),
            locale: LangService.locale,
        });
    }
}
/**
 * Global locale
 */
LangService.locale = 'es';
const Lang = LangService.create();

exports.Lang = Lang;
