/**
 * Custom hook for accessing translations
 * @param {string} key - The translation key to look up
 * @returns {string} The translated string or the key if translation not found
 */
export const useTranslation = (key) => {
    // Access the global translations object
    const translations = window.archmTranslations || {};

    // Helper function to get nested object values
    const getNestedValue = (obj, path) => {
        return path.split('.').reduce((acc, part) => {
            return acc && acc[part] !== undefined ? acc[part] : undefined;
        }, obj);
    };

    // Get the translation
    const translation = getNestedValue(translations, key);

    // Return the translation only if it's a string or number (valid React children)
    // If it's an object or undefined, return the key to avoid React error #31
    if (typeof translation === 'string' || typeof translation === 'number') {
        return translation;
    }
    return key;
};

/**
 * Hook for accessing multiple translations at once
 * @returns {Object} Object containing translation functions
 */
export const useTranslations = () => {
    return {
        t: useTranslation,
        // Add more translation-related functions here if needed
    };
};