import { a as getLang } from './helpers.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 items.",
	"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(s)",
	"datatable.active-filters": ":n active filter(s)",
	"datatable.clear-filters": "Clear all filters",
	"datatable.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.value": "Value",
	"datatable.to": "To",
	"datatable.from": "From",
	"datatable.date": "Date",
	"aria.close": "Close",
	"fields.autocomplete-results": "Showing :count suggestion(s)",
	"fields.count-more": "and :count more ...",
	"fields.list-empty": "List is empty.",
	"fields.max-options": "Maximum of :max options 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(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": "<b>Choose a file</b> or drag it here",
	"fields.cropper.sizes": "Select size",
	"fields.input.color": "Pick a color",
	"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 characters",
	"fields.validation.too-short": "This field must be at least :min characters",
	"fields.validation.type-mismatch": "The value is not valid",
	"fields.validation.value-missing": "This field is required",
	"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"
};

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 elementos en total.",
	"datatable.show-more": "mostrar mas 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(s) disponible(s)",
	"datatable.active-filters": ":n filtro(s) activo(s)",
	"datatable.clear-filters": "Limpiar todos los filtros",
	"datatable.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.value": "Valor",
	"datatable.to": "Desde",
	"datatable.from": "Hasta",
	"datatable.date": "Fecha",
	"aria.close": "Cerrar",
	"fields.autocomplete-results": "Mostrando :count recomendacion(es)",
	"fields.count-more": "y :count más ...",
	"fields.list-empty": "La lista esta vacia.",
	"fields.max-options": "Máximo de :max opciones seleccionadas. 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(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": "<b>Elija un archivo</b> o arrástrelo aquí",
	"fields.cropper.sizes": "Selecciona el tamaño",
	"fields.input.color": "Elige un color",
	"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 caracteres",
	"fields.validation.too-short": "Este campo debe tener al menos :min caracteres",
	"fields.validation.type-mismatch": "El valor no es válido",
	"fields.validation.value-missing": "Este campo es obligatorio",
	"stepper.back": "Regresar",
	"stepper.next": "Siguiente",
	"stepper.finish": "Finalizar",
	"alert.success": "¡Que 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": "Si",
	"alert.confirm-no": "No"
};

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 = 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 {
            if (Object.keys(replace).length) {
                return Object.keys(replace).reduce((text, find) => text.replace(`:${find}`, replace[find]), this._[key]);
            }
            return this._[key];
        }
        catch (error) {
            return null;
        }
    }
    /**
     * 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();

export { Lang as L };
