// ============================================================
// Tribeca Lisboa — shared i18n (EN/PT)
// Persistent (localStorage), instant switch via React context,
// synced across pages/tabs. Load FIRST on every page.
//   const [lang, setLang] = useLang();   // for App root + switchers
//   const lang = React.useContext(LangContext);  // in content
//   tt(lang, 'English', 'Português')     // pick a string
//   FIX('More than a festival')          // fixed label — always EN
// ============================================================
(function () {
  const KEY = 'tfl_lang';
  window.TFL = window.TFL || {};
  window.TFL.getLang = function () {
    try { const v = localStorage.getItem(KEY); return (v === 'EN' || v === 'PT') ? v : 'PT'; }
    catch (e) { return 'PT'; }
  };
  window.TFL.setLang = function (l) {
    if (l !== 'EN' && l !== 'PT') return;
    try { localStorage.setItem(KEY, l); } catch (e) {}
    window.dispatchEvent(new CustomEvent('tfl-lang', { detail: l }));
  };
})();

// React context holding the active language
window.LangContext = React.createContext('PT');

// Hook: live language + setter (subscribes to changes from any source)
window.useLang = function useLang() {
  const [lang, setLangState] = React.useState(window.TFL.getLang());
  React.useEffect(function () {
    const sync = function () { setLangState(window.TFL.getLang()); };
    window.addEventListener('tfl-lang', sync);
    window.addEventListener('storage', sync);
    sync();
    return function () {
      window.removeEventListener('tfl-lang', sync);
      window.removeEventListener('storage', sync);
    };
  }, []);
  return [lang, window.TFL.setLang];
};

// Pick a string by language
window.tt = function tt(lang, en, pt) { return lang === 'EN' ? en : pt; };

// Fixed product UI label — always English, in both modes
window.FIX = function FIX(s) { return s; };
