'use strict';

var React = require('react');
var AtlantisContext = require('../../AtlantisContext-cjs.js');

function defineMessages(messages) {
    return messages;
}
function useAtlantisI18n(messages) {
    const { locale } = AtlantisContext.useAtlantisContext();
    const normalizedLocale = normalizeLocale(locale);
    const t = React.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",
    },
});

exports.commonMessages = commonMessages;
exports.defineMessages = defineMessages;
exports.useAtlantisI18n = useAtlantisI18n;
