
import { translations } from './translations';

let currentLang: 'en' | 'es' = 'en';

function updateUI() {
  const t = translations[currentLang];
  
  // Update elements with data-t attribute
  document.querySelectorAll('[data-t]').forEach((el) => {
    const key = el.getAttribute('data-t');
    if (key && t[key as keyof typeof t]) {
      el.textContent = t[key as keyof typeof t];
    }
  });

  // Update specific elements that need special handling
  const promoBanner = document.getElementById('promo-banner');
  if (promoBanner) promoBanner.textContent = t.promoBanner;

  const langText = document.getElementById('lang-text');
  if (langText) langText.textContent = currentLang.toUpperCase();

  // Update all call numbers
  document.querySelectorAll('.call-number-span').forEach(el => {
    el.textContent = t.callNumber;
  });

  document.querySelectorAll('a[href^="tel:"]').forEach(el => {
    el.setAttribute('href', `tel:${t.callNumber.replace(/[^0-9]/g, '')}`);
  });
}

// Language Toggle Logic
const langToggle = document.getElementById('lang-toggle');
if (langToggle) {
  langToggle.addEventListener('click', () => {
    currentLang = currentLang === 'en' ? 'es' : 'en';
    updateUI();
  });
}

// Initial load
updateUI();
