import { useCallback } from 'react';
import { u as useAtlantisContext } from '../../AtlantisContext-es.js';

function defineMessages(messages) {
    return messages;
}
function useAtlantisI18n(messages) {
    const { locale } = useAtlantisContext();
    const normalizedLocale = normalizeLocale(locale);
    const t = useCallback((messageKey, values) => {
        return interpolateMessage(resolveMessage(messages[messageKey], normalizedLocale), values);
    }, [normalizedLocale, messages]);
    return { locale: normalizedLocale, t };
}
function resolveMessage(message, normalizedLocale) {
    var _a, _b;
    const baseLocale = normalizedLocale.split("-")[0];
    return (_b = (_a = message[normalizedLocale]) !== null && _a !== void 0 ? _a : message[baseLocale]) !== null && _b !== void 0 ? _b : message.en;
}
function normalizeLocale(locale) {
    return locale.trim().replace(/_/g, "-").toLowerCase();
}
function interpolateMessage(message, values) {
    if (!values)
        return message;
    return message.replace(/\{(\w+)\}/g, (placeholder, key) => {
        const value = values[key];
        return value === undefined ? placeholder : String(value);
    });
}

const commonMessages = defineMessages({
    Loading: {
        en: "Loading",
        es: "Cargando",
    },
    Confirm: {
        en: "Confirm",
        es: "Confirmar",
    },
    Cancel: {
        en: "Cancel",
        es: "Cancelar",
    },
});

export { commonMessages, defineMessages, useAtlantisI18n };
