
// i18n context + translations
const translations = {
  en: {
    nav: {
      about: "About",
      skills: "Skills",
      projects: "Projects",
      contact: "Contact",
    },
    hero: {
      role: "Junior Dev",
      location: "Liège, Belgium",
      scroll: "Scroll",
    },
    about: {
      label: "About",
      bio1: "Third-year app dev student, curious by nature and a bit of a generalist. I enjoy learning things I had no idea about the day before and figuring stuff out as I go.",
      bio2: "Currently looking for an internship, open to most things, especially if there's something new to learn. The medical sector is somewhere I'd genuinely like to end up.",
      facts: {
        location: "Location",
        locationVal: "Liège, Belgium",
        status: "Status",
        statusVal: "Looking for an internship",
        interests: "Interests",
        interestsVal: "Gaming, pop culture, tech & a bit of everything",
      },
    },
    skills: {
      label: "Skills",
      title: "Technologies",
      subtitle: "A selection of tools I work with daily.",
    },
    projects: {
      label: "Projects",
      live: "Live",
      repo: "Repo",
      wip: "WIP",
      loading: "Loading projects",
      empty: "No projects yet",
    },
    contact: {
      label: "Contact",
      title: "Let's work\ntogether.",
      subtitle: "Don't hesitate to reach out, always up for a chat.",
      email: "contact@muuqi.dev",
      presence: "Discord presence",
      presenceOffline: "Currently offline",
      presenceOnline: "Online",
    },
  },
  fr: {
    nav: {
      about: "À propos",
      skills: "Compétences",
      projects: "Projets",
      contact: "Contact",
    },
    hero: {
      role: "Dev Junior",
      location: "Liège, Belgium",
      scroll: "Défiler",
    },
    about: {
      label: "À propos",
      bio1: "Étudiant en B3 devapp, curieux et touche-à-tout dans l'âme. J'aime m'instruire, apprendre des trucs que je ne connaissais pas la veille et comprendre comment les choses fonctionnent.",
      bio2: "Je cherche un stage en ce moment, ouvert à pas mal de choses, surtout si ça me permet d'apprendre. Le secteur médical m'attire vraiment.",
      facts: {
        location: "Localisation",
        locationVal: "Liège, Belgium",
        status: "Statut",
        statusVal: "En recherche de stage",
        interests: "Intérêts",
        interestsVal: "Gaming, culture pop, informatique & un peu de tout",
      },
    },
    skills: {
      label: "Compétences",
      title: "Technologies",
      subtitle: "Une sélection d'outils avec lesquels je travaille quotidiennement.",
    },
    projects: {
      label: "Projets",
      live: "Live",
      repo: "Repo",
      wip: "En cours",
      loading: "Chargement des projets",
      empty: "Aucun projet pour le moment",
    },
    contact: {
      label: "Contact",
      title: "Travaillons\nensemble.",
      subtitle: "N'hésitez pas à me contacter, toujours partant pour échanger.",
      email: "contact@muuqi.dev",
      presence: "Présence Discord",
      presenceOffline: "Hors ligne",
      presenceOnline: "En ligne",
    },
  },
};

const I18nContext = React.createContext(null);

function I18nProvider({ children }) {
  const getBrowserLang = () => {
    const stored = localStorage.getItem("portfolio_lang");
    if (stored && translations[stored]) return stored;
    const nav = navigator.language?.slice(0, 2);
    return translations[nav] ? nav : "en";
  };

  const [lang, setLangState] = React.useState(getBrowserLang);

  const setLang = (l) => {
    localStorage.setItem("portfolio_lang", l);
    setLangState(l);
  };

  const t = translations[lang];

  return (
    <I18nContext.Provider value={{ lang, setLang, t, languages: Object.keys(translations) }}>
      {children}
    </I18nContext.Provider>
  );
}

function useI18n() {
  return React.useContext(I18nContext);
}

Object.assign(window, { I18nProvider, useI18n });
