/* eslint-disable react-refresh/only-export-components */
/**
 * LanguageContext
 * Exposes the current UI language together with helpers for static UI labels
 * and language-specific fields returned from atlas and annotation data.
 */
import React, { createContext, useState, useContext } from 'react';
import { uiTranslations } from './translations';

const LanguageContext = createContext();

export const LanguageProvider = ({ children }) => {
  const [lang, setLang] = useState('cs');

  const t = (key) => uiTranslations[lang][key] || key;

  const l = (obj, field) => {
    if (!obj) return '';
    return obj[`${field}_${lang}`] || obj[field];
  };

  return (
    <LanguageContext.Provider value={{ lang, setLang, t, l }}>
      {children}
    </LanguageContext.Provider>
  );
};

export const useLanguage = () => useContext(LanguageContext);