/* global React */
/* ============================================================
   i18n: EN + 中文 (zh)
   Use:  const { t, lang, setLang } = useT();
         <h1>{t('hero.titleA')}</h1>
   ============================================================ */

const VP_LANGS = ["en", "zh"];

const TRANSLATIONS = {
  en: {
    "nav.pets":         "Pets",
    "nav.sounds":       "Sounds",
    "nav.download":     "Download",
    "nav.lang.en":      "EN",
    "nav.lang.zh":      "中",

    /* Hero */
    "hero.titleA1":     "Your AI,",
    "hero.titleA2":     "alive.",
    "hero.subA":        "Multi AI agents on your Mac. Zero of them talk to each other. VibePet turns that chaos into a single pixel pet living in the notch.",
    "hero.titleB1":     "One capsule.",
    "hero.titleB2":     "Eight agents.",
    "hero.subB":        "Claude Code waits. Codex hits a limit. Cursor finishes a review. Your pet's mood tells you who needs you — in a glance.",
    "hero.titleC1":     "A pet that watches",
    "hero.titleC2":     "so you don't have to.",
    "hero.subC":        "Native macOS. Lives in the notch. Folds eight AI coding tools into one calm pulse — and never logs a single token of what you write.",
    "hero.download":    "Download for macOS",
    "hero.npx":         "npx vibepet install",
    "hero.stat.mem":    "< 60MB Mem",
    "hero.stat.cpu":    "< 0.5% idle CPU",
    "hero.caption":     "MacBook · real notch · hover or click the island",
    "hero.hint":        "Hover to expand · click to lock open · use the chips to cycle states",

    /* Chaos → Calm */
    "chaos.eyebrow":    "The problem",
    "chaos.title.pre":  "Multi AI agents.",
    "chaos.title.zero": "Zero",
    "chaos.title.post": "of them talk to each other.",
    "chaos.sub":        "Your menu bar fills with notifications you didn't ask for. One agent is waiting, another rate-limited, another silently finished an hour ago. You miss the one that mattered.",
    "chaos.left":       "Today, your menu bar",
    "chaos.arrow":      "collapses into",
    "chaos.right":      "With VibePet",

    /* Chaos cards */
    "chaos.card.1.title": "Approval requested",
    "chaos.card.1.body":  "Run 'pnpm install' in the worktree root?",
    "chaos.card.2.title": "Rate limit hit",
    "chaos.card.2.body":  "Quota refreshes at 15:30. 47 messages queued.",
    "chaos.card.3.title": "Auth expired",
    "chaos.card.3.body":  "Re-authorize gemini-cli — token issued 31d ago.",
    "chaos.card.4.title": "Review ready · 6 files",
    "chaos.card.4.body":  "src/api/* — 3 suggestions, 1 risk flagged.",
    "chaos.card.5.title": "Droid finished branch",
    "chaos.card.5.body":  "feat/onboard-flow · 17 commits, ready to merge.",
    "chaos.card.6.title": "Shell write requested",
    "chaos.card.6.body":  "Allow writes to ~/.config/?",

    /* How it works */
    "how.eyebrow":      "How it works",
    "how.title":        "Three states. No new app to learn.",
    "how.sub":          "VibePet behaves like the system, not an overlay. The same surface contracts and expands as needed.",
    "how.01.title":     "Glance",
    "how.01.body":      "Pet sits in the notch at menu-bar height. Color, posture, one short ticker — that's all you need.",
    "how.01.caption":   "Collapsed · pet + ticker",
    "how.02.title":     "Hover",
    "how.02.body":      "Active tool, current quota, latest message — under 300ms. Same surface, more density.",
    "how.02.caption":   "Hover · status bleeds through",
    "how.03.title":     "Jump",
    "how.03.body":      "Click to lock open. Authorize, mark read, or jump straight back to the source.",
    "how.03.caption":   "Expanded · message hub",
    "how.footprint.mem":      "resident memory",
    "how.footprint.cpu":      "idle CPU",
    "how.footprint.binary":   "zero daemons, zero electron",

    /* Eight tools */
    "tools.eyebrow":    "Coverage",
    "tools.title":      "Eight tools. One capsule.",
    "tools.sub":        "VibePet adapts to whichever agent stack you run. Each tool keeps its own surface — VibePet only adds a pulse.",
    "tools.preview.idle":   "HOVER A TOOL · preview a real message",
    "tools.preview.active": "INSIDE VIBEPET · this is how it appears",
    "tools.footer":     "· Authentication, quotas and transcripts read locally · no proxy",
    "tools.purpose.claude-code": "Editing + transcripts",
    "tools.purpose.codex":       "Long-running runs",
    "tools.purpose.cursor":      "IDE + agent wrapper",
    "tools.purpose.gemini":      "Quota-heavy workflows",
    "tools.purpose.trae":        "Multi-step planning",
    "tools.purpose.copilot-cli": "Terminal completions",
    "tools.purpose.factory":     "Async fleet runs",
    "tools.purpose.opencode":    "Self-hosted agents",

    /* Pet personality */
    "pets.eyebrow":     "Personality",
    "pets.title":       "Your pet is your status language.",
    "pets.sub":         "Eight base states. Each pet expresses them differently — same vocabulary, different dialect. Hover any sprite to see it shift.",
    "pets.state.idle":         "Idle",
    "pets.state.running":      "Running",
    "pets.state.waitingInput": "Waiting",
    "pets.state.approval":     "Approval",
    "pets.state.review":       "Review",
    "pets.state.rateLimit":    "Rate-limited",
    "pets.state.error":        "Error",
    "pets.state.sleeping":     "Sleeping",
    "pets.hatch.prefix":  "describe",
    "pets.hatch.value":   "sleepy panda who loves debugging, slow blink",
    "pets.hatch.cta":     "Hatch",
    "pets.hatch.meta1":   "Compatible with",
    "pets.hatch.meta.link": "Codex pets protocol",
    "pets.hatch.meta2":   "· supports .pet.json / .codexpet · one-click import from the community",

    /* Sounds */
    "sounds.eyebrow":   "Sound",
    "sounds.title":     "Glance with your ears.",
    "sounds.sub":       "Different events deserve different sounds. Tap any to preview — bind your own local audio file in seconds, route per-tool, mute when focus mode is on.",
    "sounds.foot":      "Want your own sounds? Drag any local audio file in and bind it to any state — your pet, your sound library.",
    "sounds.1.name":    "Auth Blip",
    "sounds.1.cat":     "Authorization",
    "sounds.1.desc":    "Quick acknowledgement chirp.",
    "sounds.2.name":    "Done Bell",
    "sounds.2.cat":     "Done",
    "sounds.2.desc":    "A soft mallet — fits a quiet room.",
    "sounds.3.name":    "Yawn",
    "sounds.3.cat":     "Rate Limit",
    "sounds.3.desc":    "Plays when your pet hits a rate limit.",

    /* Privacy / local first */
    "local.eyebrow":    "Privacy",
    "local.title1":     "Local-first.",
    "local.title2":     "Period.",
    "local.sub":        "VibePet reads files your AI tools already write. Nothing leaves your Mac — no telemetry, no cloud sync, no opt-in opt-out dance.",
    "local.card.1.title": "Events stay on your Mac.",
    "local.card.1.body":  "Written to a single append-only file. Open it in any editor. Delete it whenever.",
    "local.card.2.title": "Prompts and code, never logged.",
    "local.card.2.body":  "VibePet records that a tool ran, what state it's in, and when. Not what you wrote.",
    "local.card.3.title": "Your audit log to read or wipe.",
    "local.card.3.body":  "One command clears history. One flag turns off persistence entirely.",
    "local.log.note":     "No prompt content. No file diffs. No tokens. No network egress.",

    /* Download */
    "dl.eyebrow":       "Get it",
    "dl.title":         "One binary. Drag and drop.",
    "dl.sub":           "Universal .dmg. Notarized. macOS 13+. Drop in /Applications, grant accessibility, you're done.",
    "dl.cta":           "Download VibePet · 10 MB",
    "dl.meta":          "macOS 13 Ventura · 14 Sonoma · 15 Sequoia · signed & notarized",

    /* Footer */
    "foot.brand":       "Made for the multi-agent age. A Mac-native companion for people who run too many AI tools.",
    "foot.col.product": "PRODUCT",
    "foot.col.product.pets":    "Pets",
    "foot.col.product.sounds":  "Sounds",
    "foot.col.product.tools":   "AI Tools",
    "foot.col.product.download":"Download",
    "foot.col.community": "COMMUNITY",
    "foot.col.legal":   "LEGAL",
    "foot.col.legal.privacy": "Privacy",
    "foot.col.legal.terms":   "Terms",
    "foot.copy":        "Made for the multi-agent age.",
    "foot.status":      "all systems pulsing",
  },

  zh: {
    "nav.pets":         "宠物",
    "nav.sounds":       "音效",
    "nav.download":     "下载",
    "nav.lang.en":      "EN",
    "nav.lang.zh":      "中",

    /* Hero */
    "hero.titleA1":     "让你的 AI，",
    "hero.titleA2":     "活起来。",
    "hero.subA":        "Mac 上跑着一堆 AI agent，它们却互不知情。VibePet 把这些纷乱信号收拢成刘海里的一只像素小宠物。",
    "hero.titleB1":     "一颗胶囊。",
    "hero.titleB2":     "八个 agent。",
    "hero.subB":        "Claude Code 等待中、Codex 触发限速、Cursor 完成代码评审。一眼看小宠物的情绪，就知道谁在等你。",
    "hero.titleC1":     "一只替你盯着的宠物，",
    "hero.titleC2":     "你不用再分心。",
    "hero.subC":        "原生 macOS、栖息于刘海。八款 AI 编码工具被折叠成一束平静的脉搏 —— 而你写下的每一个 token，永远只属于你。",
    "hero.download":    "下载 macOS 客户端",
    "hero.npx":         "npx vibepet install",
    "hero.stat.mem":    "< 60MB 内存",
    "hero.stat.cpu":    "< 0.5% 空闲 CPU",
    "hero.caption":     "MacBook · 真实刘海 · 悬停或点击宠物岛",
    "hero.hint":        "悬停展开 · 点击锁定 · 下方按钮可切换状态",

    /* Chaos → Calm */
    "chaos.eyebrow":    "痛点",
    "chaos.title.pre":  "多个 AI agent。",
    "chaos.title.zero": "零",
    "chaos.title.post": "通信。",
    "chaos.sub":        "菜单栏被你没要求过的通知塞满。一个在等你授权、一个被限速、一个一小时前就悄悄跑完了。最重要的那条，往往就这么错过。",
    "chaos.left":       "当下：你的菜单栏",
    "chaos.arrow":      "收拢为",
    "chaos.right":      "使用 VibePet",

    "chaos.card.1.title": "等待授权",
    "chaos.card.1.body":  "在 worktree 根目录执行 'pnpm install'？",
    "chaos.card.2.title": "触发限速",
    "chaos.card.2.body":  "15:30 后恢复 · 已排队 47 条消息。",
    "chaos.card.3.title": "鉴权过期",
    "chaos.card.3.body":  "请重新登录 gemini-cli — token 已签发 31 天。",
    "chaos.card.4.title": "评审就绪 · 6 个文件",
    "chaos.card.4.body":  "src/api/* — 3 条建议、1 条风险。",
    "chaos.card.5.title": "Droid 完成分支",
    "chaos.card.5.body":  "feat/onboard-flow · 17 次提交、可合并。",
    "chaos.card.6.title": "请求写入权限",
    "chaos.card.6.body":  "允许写入 ~/.config/？",

    /* How it works */
    "how.eyebrow":      "运行方式",
    "how.title":        "三种状态。无需学习新应用。",
    "how.sub":          "VibePet 不是浮层，而是系统的延伸。同一个胶囊会按需收起和展开。",
    "how.01.title":     "一眼",
    "how.01.body":      "宠物栖息在刘海里，与菜单栏同高。颜色、姿态、一句滚动条 —— 就够了。",
    "how.01.caption":   "收起 · 宠物 + 滚动条",
    "how.02.title":     "悬停",
    "how.02.body":      "活动工具、当前配额、最新一条消息 —— 300ms 内呈现。同一表面，密度更高。",
    "how.02.caption":   "悬停 · 状态显形",
    "how.03.title":     "跳转",
    "how.03.body":      "点击锁定打开。授权、标记已读，或一键跳回源头。",
    "how.03.caption":   "展开 · 消息中心",
    "how.footprint.mem":     "常驻内存",
    "how.footprint.cpu":     "空闲 CPU",
    "how.footprint.binary":  "零守护进程、零 electron",

    /* Eight tools */
    "tools.eyebrow":    "覆盖范围",
    "tools.title":      "八款工具。一颗胶囊。",
    "tools.sub":        "VibePet 适配你手上任意 agent 组合。每个工具仍保留自己的入口 —— VibePet 只是为它们加上一束共同的脉搏。",
    "tools.preview.idle":   "悬停查看 · 预览真实消息",
    "tools.preview.active": "在 VIBEPET 内部 · 它会这样呈现",
    "tools.footer":     "· 鉴权、配额、记录均在本地读取 · 无中转",
    "tools.purpose.claude-code": "编辑 + 会话记录",
    "tools.purpose.codex":       "长时任务",
    "tools.purpose.cursor":      "IDE + agent 集成",
    "tools.purpose.gemini":      "高配额工作流",
    "tools.purpose.trae":        "多步规划",
    "tools.purpose.copilot-cli": "终端补全",
    "tools.purpose.factory":     "异步舰队任务",
    "tools.purpose.opencode":    "自托管 agent",

    /* Pet personality */
    "pets.eyebrow":     "性格",
    "pets.title":       "你的宠物，就是你的状态语言。",
    "pets.sub":         "八种基础状态。每只宠物以自己的方式表达 —— 同一套词汇，不同方言。悬停任一精灵图查看变化。",
    "pets.state.idle":         "空闲",
    "pets.state.running":      "运行中",
    "pets.state.waitingInput": "等待输入",
    "pets.state.approval":     "等待授权",
    "pets.state.review":       "评审就绪",
    "pets.state.rateLimit":    "已限速",
    "pets.state.error":        "出错",
    "pets.state.sleeping":     "休眠",
    "pets.hatch.prefix":  "描述",
    "pets.hatch.value":   "一只爱 debug 的瞌睡熊猫，慢眨眼",
    "pets.hatch.cta":     "孵化",
    "pets.hatch.meta1":   "兼容",
    "pets.hatch.meta.link": "Codex pets 协议",
    "pets.hatch.meta2":   "· 支持 .pet.json / .codexpet · 一键导入社区作品",

    /* Sounds */
    "sounds.eyebrow":   "声音",
    "sounds.title":     "用耳朵感知状态。",
    "sounds.sub":       "不同事件，不同声音。点击任意预览 —— 把任意本地音频绑给任意状态，按工具分发，专注模式自动静音。",
    "sounds.foot":      "想要专属的提示音？拖入任意本地音频文件，绑定到任意状态 —— 你的小宠物，你的声音库。",
    "sounds.1.name":    "授权提示",
    "sounds.1.cat":     "授权",
    "sounds.1.desc":    "一声轻快的确认音。",
    "sounds.2.name":    "完成铃",
    "sounds.2.cat":     "完成",
    "sounds.2.desc":    "柔和的木槌 —— 适合安静的房间。",
    "sounds.3.name":    "打哈欠",
    "sounds.3.cat":     "限速",
    "sounds.3.desc":    "当宠物触发限速时播放。",

    /* Privacy */
    "local.eyebrow":    "隐私",
    "local.title1":     "Local-first。",
    "local.title2":     "就这么简单。",
    "local.sub":        "VibePet 只读取 AI 工具已经写出的文件。不上云、不发遥测、不弹什么 opt-in 弹窗。",
    "local.card.1.title": "事件只在你的 Mac 上",
    "local.card.1.body":  "写入一个单一的追加文件。任意编辑器可打开。随时可删除。",
    "local.card.2.title": "Prompt 与代码，从不记录",
    "local.card.2.body":  "VibePet 只记录某个工具何时进入了某个状态。不记录你写了什么。",
    "local.card.3.title": "审计日志由你掌控",
    "local.card.3.body":  "一行命令清空历史。一个开关完全关闭持久化。",
    "local.log.note":     "无 prompt 内容 · 无代码 diff · 无 token · 无网络出站",

    /* Download */
    "dl.eyebrow":       "下载",
    "dl.title":         "一个二进制。拖入即用。",
    "dl.sub":           "通用 .dmg、已公证、macOS 13+。拖入 /Applications、授予辅助功能权限，结束。",
    "dl.cta":           "下载 VibePet · 10 MB",
    "dl.meta":          "macOS 13 Ventura · 14 Sonoma · 15 Sequoia · 已签名 & 公证",

    /* Footer */
    "foot.brand":       "为「多 agent 时代」而生。一只栖息于 Mac 原生的小宠物，献给 AI 工具用太多的人。",
    "foot.col.product": "产品",
    "foot.col.product.pets":    "宠物",
    "foot.col.product.sounds":  "音效",
    "foot.col.product.tools":   "AI 工具",
    "foot.col.product.download":"下载",
    "foot.col.community": "社区",
    "foot.col.legal":   "法律",
    "foot.col.legal.privacy": "隐私政策",
    "foot.col.legal.terms":   "服务条款",
    "foot.copy":        "为「多 agent 时代」而生。",
    "foot.status":      "所有系统平稳脉动",
  },
};

const LangContext = React.createContext({ lang: "en", setLang: () => {}, t: (k) => k });

function LangProvider({ lang = "en", setLang, children }) {
  const t = React.useCallback(
    (key) => {
      const d = TRANSLATIONS[lang] || TRANSLATIONS.en;
      return d[key] ?? TRANSLATIONS.en[key] ?? key;
    },
    [lang]
  );
  const value = React.useMemo(() => ({ lang, setLang, t }), [lang, setLang, t]);
  return React.createElement(LangContext.Provider, { value }, children);
}

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

Object.assign(window, { VP_LANGS, TRANSLATIONS, LangContext, LangProvider, useT });
