// Simple i18n with FR/EN toggle persisted to localStorage

const I18N = {
  fr: {
    nav: { groupe: "GROUPE", solutions: "SOLUTIONS", engagements: "ENGAGEMENTS", talents: "TALENTS", actus: "ACTUS", projets: "PROJETS", contact: "CONTACT" },
    hero: {
      eyebrow: "Portfolio de projets",
      title: "Des champs qui produisent deux récoltes",
      titleEm: "l'une solaire, l'autre nourricière.",
      lead: "Découvrez les centrales agrivoltaïques d'Amarenco : chaque site concilie production d'énergie renouvelable et continuité de l'activité agricole, au bénéfice des territoires et des agriculteurs.",
      cta1: "Explorer les projets",
      cta2: "Comprendre l'agrivoltaïsme"
    },
    totals: {
      total: "Capacité totale opérationnelle",
      projects: "Projets dans 7 pays",
      hectares: "Hectares en coactivité",
      co2: "T CO₂ évitées / an"
    },
    filters: { all: "Tous les projets", type: "Type", country: "Pays", status: "Statut" },
    status: { operational: "Opérationnel", construction: "En construction", development: "En développement" },
    type: { agri_sheep: "Agri-PV · Ovins", agri_crops: "Agri-PV · Cultures", agri_vine: "Agri-PV · Vigne", agri_orchard: "Agri-PV · Verger" },
    card: { viewProject: "Voir le projet", commissioned: "Mise en service", capacity: "Capacité", area: "Superficie", partner: "Partenaire agricole" },
    sectionProjectsTitle: "Nos centrales agrivoltaïques",
    sectionProjectsLead: "Chaque projet est co-construit avec les agriculteurs, les collectivités et les riverains. Cliquez sur une centrale pour explorer le site en 3D.",
    footer: {
      addr: "Amarenco Group · Aix-en-Provence",
      rights: "© 2026 Amarenco. Tous droits réservés.",
      col1: "Groupe", col2: "Solutions", col3: "Engagements", col4: "Ressources"
    }
  },
  en: {
    nav: { groupe: "GROUP", solutions: "SOLUTIONS", engagements: "COMMITMENTS", talents: "CAREERS", actus: "NEWS", projets: "PROJECTS", contact: "CONTACT" },
    hero: {
      eyebrow: "Project portfolio",
      title: "Fields that yield two harvests —",
      titleEm: "one solar, one feeding us.",
      lead: "Explore Amarenco's agrivoltaic plants. Each site reconciles renewable energy production with ongoing farming activity, for the benefit of local territories and farmers.",
      cta1: "Explore projects",
      cta2: "What is agrivoltaics?"
    },
    totals: {
      total: "Total operating capacity",
      projects: "Projects across 7 countries",
      hectares: "Hectares under coactivity",
      co2: "T CO₂ avoided / year"
    },
    filters: { all: "All projects", type: "Type", country: "Country", status: "Status" },
    status: { operational: "Operational", construction: "Under construction", development: "In development" },
    type: { agri_sheep: "Agri-PV · Sheep", agri_crops: "Agri-PV · Crops", agri_vine: "Agri-PV · Vineyard", agri_orchard: "Agri-PV · Orchard" },
    card: { viewProject: "View project", commissioned: "Commissioned", capacity: "Capacity", area: "Area", partner: "Farming partner" },
    sectionProjectsTitle: "Our agrivoltaic plants",
    sectionProjectsLead: "Each project is co-built with farmers, local authorities and residents. Click a plant to explore the site in 3D.",
    footer: {
      addr: "Amarenco Group · Aix-en-Provence",
      rights: "© 2026 Amarenco. All rights reserved.",
      col1: "Group", col2: "Solutions", col3: "Commitments", col4: "Resources"
    }
  }
};

function useLang() {
  const [lang, setLang] = React.useState(() => localStorage.getItem("am_lang") || "fr");
  React.useEffect(() => { localStorage.setItem("am_lang", lang); document.documentElement.lang = lang; }, [lang]);
  return [lang, setLang];
}

function t(lang, path) {
  return path.split(".").reduce((o, k) => (o ? o[k] : null), I18N[lang]) ?? path;
}

window.I18N = I18N;
window.useLang = useLang;
window.t = t;
