// Neurasea web — shared bilingual layer for Business + Exchange pages
// Exports to window: WebLangCtx, useWebLang, useT
// Pattern: English source string is the key. t('Suppliers') · t('{n} accounts', {n:42})

const WEB_ZH = {
  // ── shared chrome ──────────────────────────────────────────
  "Sign in": "登录",
  "Get started": "开始使用",
  "Book a demo": "预约演示",
  "Talk to sales": "联系销售",
  "English": "English",
  "中文": "中文",
  "Markets open": "市场开放",
  "Live": "实时",

  // ── B2B nav ────────────────────────────────────────────────
  "Platform": "平台",
  "For Suppliers": "面向供应方",
  "For Consumers": "面向消耗方",
  "For Customers": "面向个人用户",
  "One client. Every subscription becomes power.": "一个客户端，让每份订阅都变成电力。",
  "The Neurasea desktop client turns the AI subscriptions on your Mac into grid power sources — supply idle quota, earn credits, and draw any model with them. Here is how it works.": "Neurasea 桌面客户端把你 Mac 上的 AI 订阅变成电网电源——共享闲置额度、赚取积分，并用积分取用任意模型。使用方法如下。",
  "Install — it finds your subscriptions": "安装——自动发现你的订阅",
  "Open the app once and it detects the AI subscriptions already signed in on this Mac — Claude, ChatGPT, Gemini, Copilot. No copy-pasting keys, nothing leaves your device.": "首次打开应用，它会自动检测这台 Mac 上已登录的 AI 订阅——Claude、ChatGPT、Gemini、Copilot。无需复制密钥，数据不离开你的设备。",
  "Auto-detects signed-in accounts": "自动检测已登录账号",
  "Credentials stay local, sandboxed": "凭据仅保存在本地，沙箱隔离",
  "Setup takes under a minute": "设置不到一分钟",
  "Flip \u201cFeed the grid\u201d on idle quota": "为闲置额度打开「并网供电」",
  "Each subscription becomes a power source. Share the quota you are not using and earn credits — Power saver auto-stops supplying before an account runs low, so your own usage always comes first.": "每份订阅都成为一个电源。共享你用不到的额度即可赚取积分——「节电模式」会在账号额度偏低前自动停止供电，你自己的使用永远优先。",
  "Per-account supply toggle & reserve floor": "按账号控制供电开关与保留底线",
  "Power saver protects your own quota": "节电模式保护你自己的额度",
  "Or keep a source fully private": "也可以让某个电源完全私有",
  "Draw any model, watch credits flow": "取用任意模型，实时查看积分流动",
  "The overview shows your charge in real time: what your sources earned, what your draws cost. Use any model on the grid — your idle Claude quota can pay for your GPT calls.": "总览页实时显示你的电量：电源赚了多少、取用花了多少。可使用电网上的任意模型——闲置的 Claude 额度也能支付你的 GPT 调用。",
  "One balance across every model": "所有模型共用一个余额",
  "Live earned vs. spent, per session": "实时收支明细，精确到每次会话",
  "Local endpoint for agents & IDEs": "为 Agent 和 IDE 提供本地端点",
  "Get the Neurasea client": "获取 Neurasea 客户端",
  "Free to install. Your credentials never leave your device — only signed, sandboxed requests touch the grid.": "免费安装。你的凭据绝不离开设备——只有经签名、沙箱化的请求会接触电网。",
  "Download for macOS": "下载 macOS 版",
  "macOS 13+ · Windows coming soon": "macOS 13+ · Windows 版即将推出",
  "Pricing": "价格",
  "Docs": "文档",
  "Neurasea for Business": "Neurasea 企业版",
  "Business": "企业版",

  // ── Landing hero ───────────────────────────────────────────
  "The wholesale grid for AI inference": "AI 推理的批发电网",
  "Suppliers bring account inventory or API keys. Consumers subscribe for the cheapest tokens at guaranteed quality. Neurasea is the exchange in between — pooling, balancing and settling every request.": "供应方提供账号库存或 API 密钥，消耗方以订阅方式获取价格最低、质量达标的 token。Neurasea 就是中间的交易所——汇聚、调度并结算每一次请求。",
  "Become a supplier": "成为供应方",
  "Buy tokens": "购买 token",
  "No client to install · bulk-import your pool in minutes": "无需安装客户端 · 几分钟批量导入号池",

  // ── Trust stats ────────────────────────────────────────────
  "Active suppliers": "活跃供应方",
  "Models served": "可服务模型",
  "Tokens / day": "每日 token",
  "Avg. saving vs list": "相较官网均价节省",
  "Uptime SLA": "可用性 SLA",

  // ── Two paths ──────────────────────────────────────────────
  "Two sides of the grid": "电网的两端",
  "One exchange clears both — supply meets demand at the best price.": "同一个交易所撮合两端——供需在最优价格成交。",
  "Suppliers": "供应方",
  "Consumers": "消耗方",
  "API resellers & account holders": "API 中转商与账号持有者",
  "Token users & product teams": "Token 使用者与产品团队",
  "Turn idle account inventory into revenue. Import ready-made accounts or API keys in bulk — no client, no per-account fiddling.": "把闲置的账号库存变成收入。批量导入成品号或 API 密钥——无需客户端，无需逐个账号操作。",
  "Subscribe and draw any model. You never see the upstream — only the lowest price and a quality guarantee.": "订阅后即可取用任意模型。你看不到上游——只看到最低价格和质量保证。",
  "Bulk import — CLI, cloud browser, or sandbox": "批量导入——CLI、云端浏览器或沙箱",
  "Pool management, quota & load balancing": "号池管理、额度与负载均衡",
  "Daily revenue & instant settlement": "每日营收与即时结算",
  "Cheapest token price, always": "始终最低的 token 价格",
  "99.9% quality SLA across every model": "全模型 99.9% 质量 SLA",
  "Spot pay-as-you-go or weekly futures": "现货按量计费或按周期货",
  "Explore the supplier console": "查看供应方控制台",
  "See consumer plans": "查看消耗方套餐",

  // ── How it works ───────────────────────────────────────────
  "How the grid clears": "电网如何撮合",
  "Supply comes in": "供给接入",
  "Suppliers import accounts or keys. Credentials are sandboxed; we never expose them downstream.": "供应方导入账号或密钥。凭据被沙箱隔离，绝不向下游暴露。",
  "The exchange balances": "交易所调度",
  "Every request is routed to the cheapest healthy supplier that meets the model's quality bar.": "每次请求都会被路由到满足该模型质量门槛、价格最低的健康供应方。",
  "Demand draws out": "需求取用",
  "Consumers subscribe and call any model through one endpoint — blind to the upstream, sure of the price.": "消耗方订阅后通过统一端点调用任意模型——对上游无感，对价格笃定。",

  // ── Quality / trust band ───────────────────────────────────
  "Quality is not negotiable": "质量不可妥协",
  "Every supplier account is continuously probed for model identity, response quality and latency. Anything that drifts is cooled out of the pool before a single request reaches it.": "每个供应方账号都会被持续探测模型身份、响应质量与延迟。一旦发生漂移，会在任何请求到达之前被冷却出池。",
  "Model-identity verification": "模型身份校验",
  "Continuous quality probes": "持续质量探测",
  "Latency & error budgets": "延迟与错误预算",
  "Automatic supplier cool-down": "供应方自动冷却",

  // ── Footer CTA ─────────────────────────────────────────────
  "Ready to plug into the grid?": "准备好接入电网了吗？",
  "Whether you hold accounts or burn tokens, you're one import away.": "无论你持有账号还是消耗 token，只差一次导入。",

  // ── Suppliers view ─────────────────────────────────────────
  "Bring your inventory. We turn it into revenue.": "带上你的库存，我们把它变成收入。",
  "Import thousands of ready-made accounts or API keys without a desktop client. Pick the path that fits your operation — all three keep credentials sealed inside Neurasea.": "无需桌面客户端即可导入成千上万的成品号或 API 密钥。选择适合你运营方式的路径——三种方式都会把凭据封存在 Neurasea 内部。",
  "Three ways to onboard a pool": "三种接入号池的方式",
  "CLI bulk import": "CLI 批量导入",
  "Cloud serverless browser": "云端无服务器浏览器",
  "Sandbox + session vault": "沙箱 + 会话保险库",
  "Script accounts in one by one — or pipe a CSV of thousands. Best for API keys and headless credentials.": "逐个录入账号——或导入数千行的 CSV。最适合 API 密钥与无头凭据。",
  "Log into ready-made accounts in a managed cloud browser. Cookies and sessions stay in our instance — nothing on your machine.": "在托管的云端浏览器中登录成品号。Cookie 与会话保留在我们的实例中——你的设备上不留任何痕迹。",
  "Store credentials in isolated sandboxes backed by browser sessions. Built for large pools that need quota, rotation and load balancing.": "在以浏览器会话为后端的隔离沙箱中存储凭据。专为需要额度、轮换与负载均衡的大型号池打造。",
  "Recommended for API keys": "推荐用于 API 密钥",
  "Recommended for account logins": "推荐用于账号登录",
  "Recommended for large pools": "推荐用于大型号池",
  "accounts imported": "个账号已导入",
  "session active": "会话活跃",
  "sandboxes running": "个沙箱运行中",
  "Add another": "再添加一个",
  "Open cloud browser": "打开云端浏览器",
  "Manage sandboxes": "管理沙箱",
  "Supplier console": "供应方控制台",
  "A live view of your pool, earnings and load.": "你的号池、收益与负载的实时视图。",
  "Active accounts": "活跃账号",
  "kWh sold today": "今日售出 kWh",
  "Revenue · 7d": "营收 · 7天",
  "Fill rate": "成交率",
  "Account pool": "账号池",
  "Search accounts": "搜索账号",
  "PROVIDER": "供应商",
  "PLAN": "套餐",
  "STATUS": "状态",
  "LOAD": "负载",
  "QUALITY": "质量",
  "SOLD 24H": "24小时售出",
  "live": "在线",
  "cooling": "冷却中",
  "banned": "已封禁",
  "Load balancing": "负载均衡",
  "Requests are spread across healthy accounts to stay under each provider's rate ceiling.": "请求会分散到健康账号上，以保持在每个供应商的速率上限之下。",
  "Import jobs": "导入任务",
  "Payout & settlement": "结算与提现",
  "Available to withdraw": "可提现余额",
  "Next settlement": "下次结算",
  "Withdraw": "提现",
  "completed": "已完成",
  "running": "运行中",
  "queued": "排队中",
  "via CLI": "经 CLI",
  "via cloud browser": "经云端浏览器",
  "via sandbox": "经沙箱",

  // ── Exchange ───────────────────────────────────────────────
  "Neurasea Exchange": "Neurasea 交易所",
  "Exchange": "交易所",
  "Terminal": "交易终端",
  "Balance": "余额",
  "Deposit": "充值",
  "Buy AI tokens at the market's lowest price": "以市场最低价购买 AI token",
  "Spot pays as you go; futures lock a weekly rate. Either way Neurasea routes every request to the cheapest healthy supply at guaranteed quality — you never touch the upstream.": "现货按量计费，期货锁定周费率。两种方式下 Neurasea 都会把每次请求路由到价格最低的健康供给，并保证质量——你永远无需接触上游。",
  "Index price": "指数价格",
  "24h volume": "24小时成交量",
  "Avg. quality SLA": "平均质量 SLA",
  "Active suppliers": "活跃供应方",
  "All models": "全部模型",
  "Model": "模型",
  "MODEL": "模型",
  "SPOT PRICE": "现货价",
  "24H": "24小时",
  "SUPPLIERS": "供应方",
  "QUALITY": "质量",
  "LATENCY": "延迟",
  "kWh / Mtok": "kWh / 百万token",
  "Buy": "买入",
  "Buy spot": "买入现货",
  "online": "在线",
  "Spot order": "现货下单",
  "Amount": "数量",
  "Est. cost": "预计花费",
  "Avg. price": "平均价",
  "Quality guarantee": "质量保证",
  "Routed to cheapest healthy supply ≥ quality bar": "路由到满足质量门槛、价格最低的健康供给",
  "Place spot order": "提交现货单",
  "Lock a weekly rate": "锁定周费率",
  "Futures contracts prepay a week of tokens at a fixed price below the spot average. Overflow falls back to spot.": "期货合约以低于现货均价的固定价格预付一周 token。超出部分回落到现货价。",
  "WEEKLY": "每周",
  "lock price": "锁定价",
  "spot avg": "现货均价",
  "included / week": "每周包含",
  "save": "节省",
  "Lock in contract": "锁定合约",
  "Popular": "热门",
  "Your positions": "你的持仓",
  "open futures contracts": "个未平期货合约",
  "LOCKED": "已锁定",
  "vs spot": "对比现货",
  "USED": "已用",
  "EXPIRES": "到期",
  "SAVED": "已省",
  "no open positions": "暂无持仓",
  "Order book": "订单簿",
  "Asks · supply offers": "卖盘 · 供给报价",
  "Bids · buy orders": "买盘 · 买入委托",
  "Spread": "价差",
  "Last": "最新",
  "Recent trades": "近期成交",
  "PRICE": "价格",
  "SIZE": "数量",
  "TIME": "时间",
  "Watchlist": "自选",
  "Open spot order": "现货下单",
  "Open futures contract": "开立期货合约",
  "Mtok": "百万token",
  "Order type": "委托类型",
  "Market": "市价",
  "Limit": "限价",
  "Limit price": "限价",
  "Quality floor": "质量下限",
  "guaranteed": "已保证",
  "Place order": "提交委托",
  "1 kWh = 1M tokens · settled in credits": "1 kWh = 100 万 token · 以积分结算",
  "Markets": "市场",
  "Positions": "持仓",
  "Spot · pay as you go": "现货 · 按量计费",
  "Futures · weekly lock": "期货 · 周度锁价",

  // ── Consumers view ─────────────────────────────────────────
  "Lowest price. Guaranteed quality. One subscription.": "最低价格。质量保证。一份订阅。",
  "You don't care whether a request is served by a ready-made account or a raw API key — and you shouldn't have to. Subscribe, call any model, and Neurasea always routes you to the cheapest healthy supply.": "你不在乎一次请求由成品号还是裸 API 密钥提供——你本就不必在乎。订阅后调用任意模型，Neurasea 始终把你路由到价格最低的健康供给。",
  "Choose how you buy": "选择你的购买方式",
  "Spot": "现货",
  "Futures": "期货",
  "Pay only for the tokens you use, at the live market price.": "仅为你使用的 token 付费，按实时市场价计费。",
  "Lock a weekly rate below spot. Best for steady, predictable load.": "锁定低于现货的周费率。最适合稳定、可预测的负载。",
  "Starter": "入门版",
  "Growth": "成长版",
  "Scale": "规模版",
  "Enterprise": "企业版",
  "/ week": "/ 周",
  "Custom": "定制",
  "Most popular": "最受欢迎",
  "included / week": "每周包含",
  "then spot price": "超出按现货价",
  "All frontier & fast models": "全部前沿与快速模型",
  "Quality-guaranteed routing": "质量保证路由",
  "One OpenAI-compatible endpoint": "统一 OpenAI 兼容端点",
  "Priority supply & SLA": "优先供给与 SLA",
  "Dedicated capacity pools": "专属容量池",
  "Volume discounts & invoicing": "用量折扣与开票",
  "Start free": "免费开始",
  "Choose plan": "选择套餐",
  "Contact sales": "联系销售",
  "What you never deal with": "你永远无需处理的事",
  "Rate limits & banned keys": "速率限制与失效密钥",
  "Juggling many provider bills": "应付多家供应商账单",
  "Quality regressions": "质量回退",
  "Vendor lock-in": "供应商锁定",
  "Why it's cheaper": "为什么更便宜",
  "Blended supply": "混合供给",
  "Idle quota from thousands of accounts is pooled, so you ride the marginal cost — not list price.": "数千个账号的闲置额度被汇聚,因此你享受边际成本——而非官网定价。",
  "Open competition": "公开竞争",
  "Suppliers bid to serve your traffic; the cheapest healthy one always wins.": "供应方竞价服务你的流量;价格最低的健康供给总是胜出。",
  "No middlemen markup": "没有中间商加价",
  "One exchange, one settlement layer — no reseller stacking fees on top.": "一个交易所、一层结算——没有层层中转商加价。",
  "per 1M tokens": "每 100 万 token",
  "Compare to going direct": "对比直连官网",
  "Direct list price": "官网官方价",
  "On Neurasea": "在 Neurasea 上",
  "you save": "你节省",
};

const WebLangCtx = React.createContext({ lang: 'en', setLang: () => {} });
const useWebLang = () => React.useContext(WebLangCtx);

function useT() {
  const { lang } = React.useContext(WebLangCtx);
  return React.useCallback((s, vals) => {
    let out = (lang === 'zh' && WEB_ZH[s] != null) ? WEB_ZH[s] : s;
    if (vals) for (const k in vals) out = out.split('{' + k + '}').join(vals[k]);
    return out;
  }, [lang]);
}

function WebLangProvider({ children }) {
  const [lang, setLangState] = React.useState(() => localStorage.getItem('ns_web_lang') || 'en');
  const setLang = (v) => { localStorage.setItem('ns_web_lang', v); setLangState(v); };
  return <WebLangCtx.Provider value={{ lang, setLang }}>{children}</WebLangCtx.Provider>;
}

Object.assign(window, { WebLangCtx, useWebLang, useT, WebLangProvider, WEB_ZH });
