// i18n.jsx — Language context + JP/EN content dictionary for AFH site.
// Pattern: const t = useT();  then use t.heroLine1 etc.
// EN copy is reasonable best-effort — refine with real bilingual copy as needed.

const i18n = {
  jp: {
    // Nav
    navItems: ['About', 'Business', 'Solution', 'News', 'Company', 'Member'],
    navContact: 'Contact',

    // Hero
    heroLine1: 'その広告は、',
    heroLine2Pill: '人間',
    heroLine2Rest: 'にだけ',
    heroLine3: '届く。',
    heroSubA: '人間認証ID、データプラットフォーム、人間認証型アドネットワーク。',
    heroSubB: '3つの事業で、AIエージェント時代の広告基盤をつくる。',

    // About
    aboutWord: 'About',
    aboutH2: [
      '広告が、人間に届いているか',
      '分からない時代が来る。',
    ],
    aboutP1: [
      'AIエージェントの普及により、インターネット上で',
      '広告接触者の大半が人間ではなくなる時代が近づいています。',
      'すでにデジタル広告の',
      'はアドフラウドによる不正接触。',
      'AIエージェントが本格普及すれば、この比率はさらに拡大します。',
    ],
    aboutP1Stat: '5回に1回',
    aboutP2: [
      '広告が誰に届いたのか、わからない。',
      'これまでの広告業界を支えてきた計測と配信の仕組みが、',
      '根本から揺らぎはじめています。',
    ],
    aboutP3: [
      'Ads for Humanityは、この課題を解決するために設立された、',
      '博報堂ＤＹホールディングス傘下、AIエージェント時代の広告事業会社です。',
      'World IDの人間認証技術を基盤に、',
      '広告が確実に人間に届く仕組みを構築します。',
    ],
    aboutP4: [
      '広告主は、オーディエンスのプライバシーを守りながら、',
      '広告を確実に実在する人間へと配信できるメリットを享受できます。',
      '個人情報がプラットフォームを超えて閲覧されたり、',
      '利用・悪用されたりするのを防ぎます。',
    ],
    // What is World ID block
    whatIsWorldIDKickerA: 'What is',
    whatIsWorldIDKickerB: 'World ID',
    worldIDBody: 'World IDは、個人情報を明かすことなく、オンライン上で「実在する一人の人間」であることを証明できる、シンプルで信頼性の高いツールです。2026年4月現在、世界中で',
    worldIDBodyStat: '1,800万人',
    worldIDBodyTail: '近くの人がWorldIDの認証を完了しています。',

    // Media coverage band
    mediaCoverageKicker: 'Media Coverage',
    mediaCoverageSub: '人間認証型アドネットワークのメディア掲載実績',
    media1Pub: '日本経済新聞', media1Date: '2025.10.13', media1Sub: '朝刊 1面',
    media2Pub: '日本経済新聞', media2Date: '2026.06.28', media2Sub: '朝刊',
    media3Pub: '日本経済新聞', media3Date: '2024.10.09', media3Sub: '朝刊',
    media4Pub: 'MarkeZine', media4Date: '掲載', media4Sub: '「"人間だけ"に届くデジタル広告を　博報堂が目指す「未来型の広告システム」とは」',

    // Business
    businessWord: 'Business',
    businessLead1: 'World IDの普及、データの集積、',
    businessLead2: 'アドネットワークの構築。',
    businessLead3: '3つの事業が一体となって、人間にだけ広告が届く仕組みを拡大します。',
    biz: [
      { jp: 'World ID活用支援', desc: 'World IDの活用を検討する企業に対して、生体認証デバイス「Orb」の店舗設置支援や、World IDを組み込んだサービス設計のコンサルティングを提供します。' },
      { jp: 'データプラットフォーム', desc: 'Coming Soon' },
      { jp: '人間認証型アドネットワーク', desc: '人間に広告を配信する「Human-Verified Ad Network™」を運営。すべての配信記録は、改ざん不可能な証拠としてブロックチェーン上に保存されます。将来的には、人間に紐づくAIエージェントへの広告配信にも対応する予定です。' },
    ],
    techPartners: 'Technology Partners',

    // Solution
    solutionWord: 'Solution',
    solutionLeadA: 'World IDの人間認証技術を活用し、',
    solutionLeadB: 'AIエージェント時代の高効率な広告配信を実現します。',
    productKicker: 'Product',
    productNameA: 'Human-Verified',
    productNameB: 'Ad',
    productTag: 'アドフラウド抑制広告配信サービス',
    productDesc: 'World IDで認証された人間にだけ広告を配信するサービスです。配信対象者はすべて人間のため、アドフラウドによる広告費の損失を抑制します。配信実績はブロックチェーンに記録され、誰に届いたかが改竄不能なエビデンスとして保存されます。',
    metricA: { label: 'クリック率', delta: '50%', deltaPrefix: '約', suffix: '改善' },
    metricB: { label: '直帰率', delta: '15pt', deltaPrefix: '約', suffix: '改善' },
    metricNote: '※ 実証実験結果',
    metricBefore: '従来',
    metricAfter: '本商品',
    solutionCTAText: '事業提携・サービスに関するご相談など、お気軽にお問い合わせください。',

    // News
    newsWord: 'News',
    newsItems: [
      { date: '2026.08.07', title: '「Humad」ベータ版を公開しました', link: '' },
      { date: '2026.06.29', title: '株式会社Ads for Humanity 設立のお知らせ', link: 'https://www.hakuhodody-holdings.co.jp/news/corporate/2026/06/6582.html' },
      { date: '2026.06.28', title: '日本経済新聞に当社の記事が掲載されました', link: 'https://www.nikkei.com/article/DGXZQOUC105FR0Q6A610C2000000/' },
    ],

    // Company
    companyWord: 'Company',
    companyRows: [
      ['社名', '株式会社Ads for Humanity / Ads for Humanity Corporation'],
      ['設立', '2026年4月15日'],
      ['所在地', '東京都港区赤坂5-3-1'],
      ['代表者', '森田英佑'],
      ['資本金', '50,000千円'],
      ['株主', '博報堂ＤＹホールディングス（100%出資）'],
      ['事業内容', 'World ID活用支援 / データプラットフォーム / 人間認証型アドネットワーク'],
    ],

    // Member
    memberWord: 'Member',
    members: [
      { name: '矢嶋 弘毅', role: '取締役会長', sub: '博報堂ＤＹホールディングス\n取締役副社長', subSize: 11 },
      { name: '森田 英佑', role: '代表取締役社長 CEO' },
      { name: '本村 勇人', role: '取締役 COO' },
      { name: '田島 弘貴', role: 'CBO' },
      { name: '宮井 弘之', role: '取締役' },
      { name: '大八木 翼', role: 'Executive Creative Director' },
    ],

    // Contact
    contactWord: 'Contact',
    contactBodyA: '事業提携・サービスに関するご相談など、',
    contactBodyB: 'お気軽にお問い合わせください。',

    // Footer
    terms: 'ご利用規約',
    privacy: 'プライバシーポリシー',
    holdings: '博報堂ＤＹホールディングスサイト',
    copyright: '© 2026 Ads for Humanity Corporation',
  },

  en: {
    // Nav
    navItems: ['About', 'Business', 'Solution', 'News', 'Company', 'Member'],
    navContact: 'Contact',

    // Hero
    heroLine1: 'The ad reaches',
    heroLine2Pill: 'humans',
    heroLine2Rest: '',
    heroLine3: 'only.',
    heroSubA: 'Human-verified IDs, a data platform, and a Human-Verified Ad Network™.',
    heroSubB: 'Three businesses building the advertising infrastructure for the AI agent era.',

    // About
    aboutWord: 'About',
    aboutH2: [
      'An era is coming when',
      'we no longer know',
      'whether ads reach humans at all.',
    ],
    aboutP1: [
      'As AI agents proliferate, the majority of ad impressions on the internet',
      'will no longer come from humans.',
      'Already today, ',
      ' of digital ads are ad fraud.',
      'When AI agents become mainstream, this ratio will only grow.',
    ],
    aboutP1Stat: '1 in 5',
    aboutP2: [
      'We can no longer tell who an ad actually reached.',
      'The measurement and delivery infrastructure that has supported',
      'the entire advertising industry is being shaken at its foundation.',
    ],
    aboutP3: [
      'Ads for Humanity was founded to solve this problem.',
      'A subsidiary of Hakuhodo DY Holdings, we are an advertising company for the AI agent era.',
      'Built on the human-verification technology of World ID,',
      'we are constructing the infrastructure that ensures ads reach real humans.',
    ],
    aboutP4: [
      'Brands benefit by ensuring ads are delivered to real humans, while protecting the privacy of the audience, ensuring personal information is not seen, used, or exploited across platforms.',
    ],

    // What is World ID block
    whatIsWorldIDKickerA: 'What is',
    whatIsWorldIDKickerB: 'World ID',
    worldIDBody: 'World ID is a simple, secure tool that lets people prove they are unique humans online without sharing personal information. As of April 2026, nearly ',
    worldIDBodyStat: '18 million people',
    worldIDBodyTail: ' globally have a verified World ID.',

    // Media coverage band
    mediaCoverageKicker: 'Media Coverage',
    mediaCoverageSub: 'Press coverage of our Human-Verified Ad Network™',
    media1Pub: 'Nikkei', media1Date: '2025.10.13', media1Sub: 'Morning Edition, Front Page',
    media2Pub: 'Nikkei', media2Date: '2026.06.28', media2Sub: 'Morning Edition',
    media3Pub: 'Nikkei', media3Date: '2024.10.09', media3Sub: 'Morning Edition',
    media4Pub: 'MarkeZine', media4Date: 'Feature', media4Sub: '"Digital ads that reach only humans — Hakuhodo\'s vision for the future of advertising"',

    // Business
    businessWord: 'Business',
    businessLead1: 'World ID adoption, data aggregation,',
    businessLead2: 'and ad network development.',
    businessLead3: 'Three businesses working as one to expand the reach of ads — to humans only.',
    biz: [
      { jp: 'World ID Adoption Support', desc: 'For companies considering World ID adoption, we provide installation support for the "Orb" biometric device in retail spaces, and consulting on service design that integrates World ID.' },
      { jp: 'Data Platform', desc: 'Coming Soon' },
      { jp: 'Human-Verified Ad Network™', desc: 'We operate the "Human-Verified Ad Network™", which delivers ads to humans. All delivery records are stored on blockchain as tamper-proof evidence. In the future, we also plan to support delivery of ads to human-backed AI agents.' },
    ],
    techPartners: 'Technology Partners',

    // Solution
    solutionWord: 'Solution',
    solutionLeadA: 'Powered by World ID\'s human verification,',
    solutionLeadB: 'we enable high-efficiency ad delivery for the AI agent era.',
    productKicker: 'Product',
    productNameA: 'Human-Verified',
    productNameB: 'Ad',
    productTag: 'Ad fraud prevention delivery service',
    productDesc: 'A service that delivers ads only to humans verified by World ID. Since every recipient is human, ad spend loss from ad fraud is suppressed. Delivery records are written to blockchain and stored as tamper-proof evidence of who received each ad.',
    metricA: { label: 'Click Rate', delta: '50%', deltaPrefix: '+', suffix: '' },
    metricB: { label: 'Bounce Rate', delta: '15pt', deltaPrefix: '-', suffix: '' },
    metricNote: '* From a proof-of-concept trial',
    metricBefore: 'Before',
    metricAfter: 'Our product',
    solutionCTAText: 'For business inquiries and service consultations, please feel free to get in touch.',

    // News
    newsWord: 'News',
    newsItems: [
      { date: '2026.08.07', title: '"Humad" beta version is now available', link: '' },
      { date: '2026.06.29', title: 'Announcing the establishment of Ads for Humanity Corporation', link: 'https://www.hakuhodody-holdings.co.jp/news/corporate/2026/06/6582.html' },
      { date: '2026.06.28', title: 'Featured in The Nikkei', link: 'https://www.nikkei.com/article/DGXZQOUC105FR0Q6A610C2000000/' },
    ],

    // Company
    companyWord: 'Company',
    companyRows: [
      ['Name', 'Ads for Humanity Corporation'],
      ['Established', 'April 15, 2026'],
      ['Address', '5-3-1 Akasaka, Minato-ku, Tokyo, Japan'],
      ['Representative', 'Eisuke Morita'],
      ['Capital', '¥50,000,000'],
      ['Shareholder', 'Hakuhodo DY Holdings (100%)'],
      ['Business', 'World ID adoption / Data platform / Human-Verified Ad Network™'],
    ],

    // Member
    memberWord: 'Member',
    members: [
      { name: 'Hirotake Yajima', role: 'Chairman', sub: 'Hakuhodo DY Holdings\nExecutive Vice President', subSize: 11 },
      { name: 'Eisuke Morita', role: 'President & CEO' },
      { name: 'Yuto Motomura', role: 'Director, COO' },
      { name: 'Hiroki Tajima', role: 'CBO' },
      { name: 'Hiroyuki Miyai', role: 'Director' },
      { name: 'Tsubasa Oyagi', role: 'Executive Creative Director' },
    ],

    // Contact
    contactWord: 'Contact',
    contactBodyA: 'For business partnerships and service inquiries,',
    contactBodyB: 'please feel free to get in touch.',

    // Footer
    terms: 'Terms of Use',
    privacy: 'Privacy Policy',
    holdings: 'Hakuhodo DY Holdings',
    copyright: '© 2026 Ads for Humanity Corporation',
  },
};

const LangContext = React.createContext({
  lang: 'jp',
  setLang: () => { },
  t: i18n.jp,
});

function LangProvider({ children }) {
  // Read language from URL ?lang= first, fall back to localStorage, then 'jp'.
  // URL is the source of truth so search engines and shared links land on the right language.
  const readInitial = () => {
    try {
      const u = new URL(window.location.href);
      const p = u.searchParams.get('lang');
      if (p === 'en' || p === 'jp') return p;
      return localStorage.getItem('afh-lang') || 'jp';
    } catch { return 'jp'; }
  };
  const [lang, setLangState] = React.useState(readInitial);

  // Sync <html lang>, document.title, meta description on every change so each
  // language has its own crawlable snapshot.
  React.useEffect(() => {
    const t = i18n[lang] || i18n.jp;
    document.documentElement.setAttribute('lang', lang === 'en' ? 'en' : 'ja');
    document.title = lang === 'en'
      ? 'Ads for Humanity | Advertising that reaches humans only'
      : 'Ads for Humanity | 人間にだけ届く広告';
    const desc = lang === 'en'
      ? 'Ads for Humanity is a Hakuhodo DY Holdings subsidiary building the advertising infrastructure for the AI agent era — powered by World ID human verification.'
      : 'Ads for Humanityは、World IDの人間認証技術を基盤に、AIエージェント時代の広告基盤をつくる博報堂ＤＹホールディングス傘下の事業会社です。';
    const metaDesc = document.querySelector('meta[name="description"]');
    if (metaDesc) metaDesc.setAttribute('content', desc);
    const ogTitle = document.querySelector('meta[property="og:title"]');
    if (ogTitle) ogTitle.setAttribute('content', document.title);
    const ogDesc = document.querySelector('meta[property="og:description"]');
    if (ogDesc) ogDesc.setAttribute('content', desc);
    const ogLocale = document.querySelector('meta[property="og:locale"]');
    if (ogLocale) ogLocale.setAttribute('content', lang === 'en' ? 'en_US' : 'ja_JP');
    const ogUrl = document.querySelector('meta[property="og:url"]');
    const canonical = document.getElementById('canonical-link');
    const url = lang === 'en'
      ? 'https://www.adsforhumanity.co.jp/?lang=en'
      : 'https://www.adsforhumanity.co.jp/';
    if (ogUrl) ogUrl.setAttribute('content', url);
    if (canonical) canonical.setAttribute('href', url);
    const twTitle = document.querySelector('meta[name="twitter:title"]');
    if (twTitle) twTitle.setAttribute('content', document.title);
    const twDesc = document.querySelector('meta[name="twitter:description"]');
    if (twDesc) twDesc.setAttribute('content', desc);
  }, [lang]);

  const setLang = React.useCallback((l) => {
    setLangState(l);
    try { localStorage.setItem('afh-lang', l); } catch { }
    // Update URL without reloading so back/forward works and the language is shareable.
    try {
      const u = new URL(window.location.href);
      if (l === 'jp') u.searchParams.delete('lang');
      else u.searchParams.set('lang', l);
      window.history.replaceState({}, '', u.toString());
    } catch { }
  }, []);

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

function useT() {
  return React.useContext(LangContext).t;
}
function useLangCtx() {
  return React.useContext(LangContext);
}

Object.assign(window, { LangContext, LangProvider, useT, useLangCtx, i18n });
