// Internationalization layer — dictionary + React context + persistence.
// Used across desktop + mobile to drive content from a single language state.

const STRINGS = {
  fr: {
    meta: {
      title: 'Thomas Gabry · Soins Énergétiques · Grand Baie, île Maurice',
      description: "Soins énergétiques à Grand Baie, île Maurice. Libérer les blocages, rééquilibrer les flux d'énergie, retrouver l'harmonie. Praticien Thomas Gabry.",
      ogTitle: 'Thomas Gabry · Soins Énergétiques',
      ogLocale: 'fr_FR',
    },
    contact: {
      whatsappMessage: 'Bonjour Thomas, je souhaiterais réserver une séance de soin énergétique.',
      emailSubject: 'Réservation — séance de soin énergétique',
    },
    nav: {
      brand: 'THOMAS GABRY',
      about: 'À propos',
      soins: 'Soins',
      tarifs: 'Tarifs',
      temoignages: 'Témoignages',
      contact: 'Contact',
      lieu: 'Le lieu',
      cta: 'Prendre rendez-vous',
      ariaOpen: 'Ouvrir le menu',
      ariaClose: 'Fermer le menu',
    },
    hero: {
      eyebrow: 'Île Maurice · Grand Baie',
      titleA: 'soins',
      titleB: 'énergétiques',
      taglineL1: 'Libérer les blocages.',
      taglineL2: "Rééquilibrer les flux d’énergie.",
      taglineL3: "Retrouver l’harmonie.",
      taglineMobileL1: 'Libérer les blocages.',
      taglineMobileL2: 'Rééquilibrer les flux.',
      taglineMobileL3: "Retrouver l’harmonie.",
      cta: 'Prendre rendez-vous',
      hours: 'Samedis · 9h – 16h',
    },
    about: {
      eyebrow: 'À propos',
      titleA: 'Une approche',
      titleAItalic: 'simple,',
      titleB: 'sans dogme,',
      titleC: 'profondément',
      titleCItalic: 'humaine.',
      caption: 'Thomas Gabry · praticien énergétique',
      p1: "Je m’appelle Thomas Gabry. Après avoir découvert les soins énergétiques dans ma propre vie, j’ai suivi une formation certifiante pour pouvoir, à mon tour, accompagner d’autres personnes.",
      p2: "Mon parcours d’ingénieur et d’entrepreneur me permet d’être pragmatique : mon approche est simple, sans dogme et profondément respectueuse de chaque personne et de son rythme.",
      mobileTitleA: 'Une approche',
      mobileTitleBItalic: 'simple, sans dogme.',
      mobileP2: "Mon parcours d’ingénieur et d’entrepreneur me permet d’être pragmatique : une approche profondément respectueuse de chaque personne et de son rythme.",
    },
    soins: {
      eyebrow: 'Les soins',
      titleA: 'Corps,',
      titleBItalic: 'émotions,',
      titleC: 'esprit.',
      introL1: 'Les soins énergétiques agissent sur les trois plans à la fois.',
      introL2: 'La séance se fait habillé, allongé, dans un cadre paisible.',
      introL3: "Vous n’avez rien à faire d’autre que d’être là, votre énergie s’occupe du reste.",
      mobileIntro: "Les soins énergétiques agissent sur les trois plans à la fois. La séance se fait habillé, allongé, dans un cadre paisible.",
      pillarBodyTitle: 'Le corps',
      pillarBodyText: 'Relâcher les tensions, libérer les blocages installés et retrouver une circulation fluide.',
      pillarBodyMobile: 'Relâcher les tensions, libérer les blocages.',
      pillarEmotionsTitle: 'Les émotions',
      pillarEmotionsText: 'Accueillir ce qui est là, faire de la place à ce qui se présente et ouvrir doucement un nouveau rapport à soi.',
      pillarEmotionsMobile: 'Accueillir, faire de la place.',
      pillarMindTitle: "L’esprit",
      pillarMindLines: ['Apaiser le mental, retrouver la clarté', "et se reconnecter à l’essentiel,", 'à son rythme.'],
      pillarMindMobile: 'Apaiser le mental, retrouver la clarté.',
      flowEyebrow: 'Le déroulé',
      flowTitleA: 'Comment se passe',
      flowTitleB: 'une',
      flowTitleBItalic: 'séance ?',
      step1Title: 'Échange',
      step1Desc: 'On commence par un temps de parole. Vous partagez ce qui vous amène, ce que vous traversez, ce que vous cherchez en venant ici.',
      step2Title: 'Le soin',
      step2Desc: 'Allongé et habillé, dans un cadre calme. La séance dure entre 1h et 1h30 selon votre énergie et la nature du travail à faire.',
      step3Title: 'Intégration',
      step3Desc: "Un dernier temps pour mettre des mots sur ce qui s’est passé, accueillir ce qui se met en mouvement et repartir en douceur.",
    },
    tarifs: {
      eyebrow: 'Tarifs',
      titleA: 'Des séances',
      titleBItalic: 'à votre',
      titleC: 'rythme.',
      mobileTitleA: 'Des séances',
      mobileTitleBItalic: 'à votre rythme.',
      intro: "Paiement en espèces, par Juice ou par virement. Aucun engagement, aucun forfait : on avance ensemble selon ce dont vous avez besoin.",
      mobileIntro: 'Paiement en espèces, par Juice ou par virement.',
      row1Name: 'Première séance',
      row1Note: "Inclut un temps d’échange initial plus long.",
      row2Name: 'Séances suivantes',
      row2Note: 'Au rythme qui vous convient, sans engagement.',
      bookCta: 'Réserver une séance',
      replyNote: 'Réponse sous 24h',
    },
    temoignages: {
      eyebrow: 'Témoignages',
      titleA: 'Ce que',
      titleAItalic: 'disent',
      titleB: "celles et ceux qui sont passés.",
      mobileTitleB: 'les personnes accompagnées.',
      placeholderQuote: '[Témoignage à compléter — à remplacer par un retour client masculin pour équilibrer la section.]',
      placeholderQuoteMobile: '[Témoignage masculin à ajouter — placeholder à remplacer.]',
      placeholderAuthor: 'À compléter',
      placeholderLoc: '— · placeholder',
      elodieQuote: "J’ai consulté Thomas à plusieurs reprises et je suis ravie de son accompagnement comme des résultats. Professionnel, à l’écoute, bienveillant — il prend le temps d’expliquer chaque soin. Au-delà de l’accueil, ces séances m’ont apporté un vrai mieux-être : regain d’énergie, alignement, sérénité.",
      elodieMobile: "J’ai consulté Thomas à plusieurs reprises et je suis ravie de son accompagnement. Professionnel, à l’écoute, bienveillant — un vrai mieux-être après chaque séance.",
      lekshailee: 'Highly recommend Thomas. He makes you comfortable and feel very safe. It was my first energetic healing experience and I loved it.',
    },
    contact: {
      eyebrow: 'Contact',
      titleA: 'Prendre',
      titleBItalic: 'rendez-vous.',
      intro: "Pour prendre rendez-vous ou simplement poser une question, contactez-moi directement. Je réponds généralement sous 24h.",
      mobileIntro: "Pour prendre rendez-vous ou poser une question, contactez-moi directement. Je réponds généralement sous 24h.",
      labelWhatsapp: 'WhatsApp',
      labelEmail: 'Email',
      labelHours: 'Horaires',
      labelLocation: 'Lieu',
      hours: 'Samedis · 9h – 16h',
      locationValue: 'Grand Baie, île Maurice',
      locationValueMobile: 'Grand Baie, M2',
    },
    lieu: {
      eyebrow: 'Le lieu',
      titleA: 'Grand Baie,',
      titleBItalic: 'île Maurice.',
      intro: "Les séances ont lieu dans un espace calme à côté du CrossFit Grand Baie, facilement accessible depuis la M2. Stationnement disponible sur place.",
      mobileIntro: "À côté du CrossFit Grand Baie, accessible depuis la M2. Stationnement disponible sur place.",
      labelAddress: 'Adresse',
      addressValue: 'À côté du CrossFit Grand Baie',
      addressValueMobile: 'CrossFit Grand Baie',
      labelRoad: 'Voie',
      roadValue: 'Motorway M2, The Vale',
      roadValueMobile: 'M2, The Vale',
      labelPlusCode: 'Plus Code',
      plusCodeValue: 'XH8R+X6 · Grand Baie',
      plusCodeValueMobile: 'XH8R+X6',
      cta: 'Itinéraire Google Maps',
      mapTitle: 'Localisation du cabinet — Grand Baie',
    },
    footer: {
      tagline: 'Soins énergétiques · corps · émotions · esprit',
      navHeader: 'Navigation',
      contactHeader: 'Contact',
      disclaimer: "Les soins énergétiques que je propose ne constituent pas un traitement médical et ne remplacent en aucun cas un suivi médical ou psychologique. En cas de trouble de santé, consultez un professionnel de santé qualifié. Je me réserve le droit de refuser une séance si la situation l’exige.",
      disclaimerMobile: "Les soins énergétiques que je propose ne constituent pas un traitement médical et ne remplacent pas un suivi médical ou psychologique.",
      copyright: '© 2026 · Thomas Gabry',
    },
  },

  en: {
    meta: {
      title: 'Thomas Gabry · Energy Healing · Grand Baie, Mauritius',
      description: "Energy healing in Grand Baie, Mauritius. Release blockages, restore the flow of energy, find your balance. Practitioner Thomas Gabry.",
      ogTitle: 'Thomas Gabry · Energy Healing',
      ogLocale: 'en_GB',
    },
    contact: {
      whatsappMessage: "Hello Thomas, I'd like to book an energy healing session.",
      emailSubject: 'Booking — energy healing session',
    },
    nav: {
      brand: 'THOMAS GABRY',
      about: 'About',
      soins: 'Sessions',
      tarifs: 'Rates',
      temoignages: 'Testimonials',
      contact: 'Contact',
      lieu: 'Location',
      cta: 'Book a session',
      ariaOpen: 'Open menu',
      ariaClose: 'Close menu',
    },
    hero: {
      eyebrow: 'Mauritius · Grand Baie',
      titleA: 'energy',
      titleB: 'healing',
      taglineL1: 'Release blockages.',
      taglineL2: 'Restore the flow of energy.',
      taglineL3: 'Find your balance.',
      taglineMobileL1: 'Release blockages.',
      taglineMobileL2: 'Restore the flow.',
      taglineMobileL3: 'Find balance.',
      cta: 'Book a session',
      hours: 'Saturdays · 9am – 4pm',
    },
    about: {
      eyebrow: 'About',
      titleA: 'A',
      titleAItalic: 'simple,',
      titleB: 'undogmatic,',
      titleC: 'deeply',
      titleCItalic: 'human approach.',
      caption: 'Thomas Gabry · energy practitioner',
      p1: "My name is Thomas Gabry. After discovering energy healing in my own life, I trained as a certified practitioner to support others on their journey.",
      p2: "My background as an engineer and entrepreneur keeps me pragmatic: my approach is simple, undogmatic, and deeply respectful of each person and their own pace.",
      mobileTitleA: 'A simple,',
      mobileTitleBItalic: 'undogmatic approach.',
      mobileP2: "My background as engineer and entrepreneur keeps me pragmatic: an approach deeply respectful of each person and their own pace.",
    },
    soins: {
      eyebrow: 'The sessions',
      titleA: 'Body,',
      titleBItalic: 'emotions,',
      titleC: 'mind.',
      introL1: 'Energy healing works on all three planes at once.',
      introL2: 'The session takes place fully clothed, lying down, in a peaceful setting.',
      introL3: "You don't need to do anything but be there, your energy takes care of the rest.",
      mobileIntro: 'Energy healing works on all three planes at once. The session takes place fully clothed, lying down, in a peaceful setting.',
      pillarBodyTitle: 'The body',
      pillarBodyText: 'Release tensions, free deep-seated blockages, and restore a smooth circulation of energy.',
      pillarBodyMobile: 'Release tensions and free blockages.',
      pillarEmotionsTitle: 'Emotions',
      pillarEmotionsText: "Welcoming what is there, making room for what arises, and gently opening a new relationship with yourself.",
      pillarEmotionsMobile: 'Welcome and make space.',
      pillarMindTitle: 'The mind',
      pillarMindLines: ['Calming the mind, finding clarity', 'and reconnecting with what matters,', 'at your own pace.'],
      pillarMindMobile: 'Calm the mind, find clarity.',
      flowEyebrow: 'How it works',
      flowTitleA: 'What happens',
      flowTitleB: 'in a',
      flowTitleBItalic: 'session?',
      step1Title: 'Conversation',
      step1Desc: "We start with a conversation. You share what brings you here, what you're going through, what you're looking for.",
      step2Title: 'The session',
      step2Desc: 'Lying down, fully clothed, in a calm space. The session lasts between 1h and 1h30 depending on your energy and what needs to be worked on.',
      step3Title: 'Integration',
      step3Desc: 'A final moment to put words on what just happened, welcome what is shifting, and leave gently.',
    },
    tarifs: {
      eyebrow: 'Rates',
      titleA: 'Sessions',
      titleBItalic: 'at your own',
      titleC: 'pace.',
      mobileTitleA: 'Sessions',
      mobileTitleBItalic: 'at your own pace.',
      intro: "Payment by cash, Juice, or bank transfer. No commitment, no package — we move forward together based on what you need.",
      mobileIntro: 'Payment by cash, Juice, or bank transfer.',
      row1Name: 'First session',
      row1Note: 'Includes a longer initial conversation.',
      row2Name: 'Following sessions',
      row2Note: 'At a pace that suits you, no commitment.',
      bookCta: 'Book a session',
      replyNote: 'Reply within 24h',
    },
    temoignages: {
      eyebrow: 'Testimonials',
      titleA: 'What',
      titleAItalic: 'clients say',
      titleB: 'after their session.',
      mobileTitleB: 'after their session.',
      placeholderQuote: '[Testimonial to be added — to be replaced with a male client review to balance the section.]',
      placeholderQuoteMobile: '[Male testimonial to add — placeholder to be replaced.]',
      placeholderAuthor: 'To be added',
      placeholderLoc: '— · placeholder',
      elodieQuote: "I've consulted Thomas several times and I am thrilled by his support and the results. Professional, attentive, kind — he takes time to explain each session. Beyond the welcome, these sessions brought me real well-being: renewed energy, alignment, serenity.",
      elodieMobile: "I've consulted Thomas several times and am thrilled by his support. Professional, attentive, kind — real well-being after each session.",
      lekshailee: 'Highly recommend Thomas. He makes you comfortable and feel very safe. It was my first energetic healing experience and I loved it.',
    },
    contact: {
      eyebrow: 'Contact',
      titleA: 'Book a',
      titleBItalic: 'session.',
      intro: "To book a session or simply ask a question, contact me directly. I usually reply within 24 hours.",
      mobileIntro: 'To book a session or ask a question, contact me directly. I usually reply within 24 hours.',
      labelWhatsapp: 'WhatsApp',
      labelEmail: 'Email',
      labelHours: 'Hours',
      labelLocation: 'Location',
      hours: 'Saturdays · 9am – 4pm',
      locationValue: 'Grand Baie, Mauritius',
      locationValueMobile: 'Grand Baie, M2',
    },
    lieu: {
      eyebrow: 'Location',
      titleA: 'Grand Baie,',
      titleBItalic: 'Mauritius.',
      intro: 'Sessions take place in a calm space next to CrossFit Grand Baie, easily accessible from the M2. Parking available on site.',
      mobileIntro: 'Next to CrossFit Grand Baie, accessible from the M2. Parking available on site.',
      labelAddress: 'Address',
      addressValue: 'Next to CrossFit Grand Baie',
      addressValueMobile: 'CrossFit Grand Baie',
      labelRoad: 'Road',
      roadValue: 'Motorway M2, The Vale',
      roadValueMobile: 'M2, The Vale',
      labelPlusCode: 'Plus Code',
      plusCodeValue: 'XH8R+X6 · Grand Baie',
      plusCodeValueMobile: 'XH8R+X6',
      cta: 'Google Maps directions',
      mapTitle: 'Practice location — Grand Baie',
    },
    footer: {
      tagline: 'Energy healing · body · emotions · mind',
      navHeader: 'Navigation',
      contactHeader: 'Contact',
      disclaimer: 'The energy healing I offer is not a medical treatment and is in no way a substitute for medical or psychological care. If you have a health concern, please consult a qualified health professional. I reserve the right to decline a session if the situation requires it.',
      disclaimerMobile: 'The energy healing I offer is not a medical treatment and does not replace medical or psychological care.',
      copyright: '© 2026 · Thomas Gabry',
    },
  },
};

// ---------------------------------------------------------------------------
// Lang context — single source of truth for language selection
// ---------------------------------------------------------------------------
const LangContext = React.createContext({ lang: 'fr', setLang: () => {} });

function detectInitialLang() {
  try {
    const saved = localStorage.getItem('lang');
    if (saved === 'fr' || saved === 'en') return saved;
  } catch (e) { /* localStorage unavailable */ }
  // Default to French (the site's primary language).
  // Only switch to English when the browser is explicitly English.
  const nav = (typeof navigator !== 'undefined' && navigator.language) ? navigator.language.toLowerCase() : '';
  return nav.startsWith('en') ? 'en' : 'fr';
}

function LangProvider({ children }) {
  const [lang, setLang] = React.useState(detectInitialLang);

  React.useEffect(() => {
    try { localStorage.setItem('lang', lang); } catch (e) {}
    document.documentElement.lang = lang;
    const meta = STRINGS[lang].meta;
    document.title = meta.title;
    const setMeta = (selector, attr, value) => {
      const el = document.querySelector(selector);
      if (el) el.setAttribute(attr, value);
    };
    setMeta('meta[name="description"]', 'content', meta.description);
    setMeta('meta[property="og:title"]', 'content', meta.ogTitle);
    setMeta('meta[property="og:description"]', 'content', meta.description);
    setMeta('meta[property="og:locale"]', 'content', meta.ogLocale);
  }, [lang]);

  const value = React.useMemo(() => ({ lang, setLang, t: STRINGS[lang] }), [lang]);
  return <LangContext.Provider value={value}>{children}</LangContext.Provider>;
}

function useLang() {
  return React.useContext(LangContext);
}

Object.assign(window, { STRINGS, LangContext, LangProvider, useLang });
