/* global React */
// i18n — Chinese / English translations
// Auto-detects browser language, persists user choice in localStorage.

const TRANSLATIONS = {
  zh: {
    // Topnav
    "nav.why": "為何而生",
    "nav.solution": "關於服務",
    "nav.features": "特點介紹",
    "nav.console": "線上簡訊管理",
    "nav.telegram": "Telegram 支援",
    "nav.who": "誰適合我們",
    "nav.learn": "了解更多",

    // Hero
    "hero.eyebrow": "v2 · 線上管理後台已上線",
    "hero.title1": "Your",
    "hero.titleSMS": "SMS",
    "hero.title2": "Postman.",
    "hero.sub.before": "為多門號使用者打造的",
    "hero.sub.strong": "簡訊集中收件中心",
    "hero.sub.after": "。一個帳號、一個畫面、所有門號的訊息即時送達。",
    "hero.cta.learn": "了解更多",
    "hero.cta.demo": "觀看後台展示",
    "hero.meta.numbers": "Max.32",
    "hero.meta.numbersLbl": "門號數量/單一GATEWAY",
    "hero.meta.delay": "< 3s",
    "hero.meta.delayLbl": "收件延遲",
    "hero.meta.uptimeLbl": "服務穩定",
    "hero.meta.saving": "Hareware Saving",
    "hero.meta.savingLbl": "萬元起跳",
    "hero.bubble1.from": "中華電信 · 0987-***-321",
    "hero.bubble1.body": "驗證碼",
    "hero.bubble2.from": "蝦皮購物 · 0912-***-815",
    "hero.bubble2.body": "訂單",
    "hero.bubble2.body2": "已出貨",
    "hero.bubble3.from": "LINE PAY · 0939-***-777",
    "hero.bubble3.body": "完成扣款",

    // Compare (痛點/解法)
    "compare.eyebrow": "痛點 / 解法",
    "compare.title1": "多門號的人，",
    "compare.title2": "都有一個共同的麻煩。",
    "compare.desc": "SIM 卡分散在不同手機裝置、不同 SIM 卡槽，重要驗證碼總是要翻來翻去，一下發現手機，一下發現手機電池壞了，手機帶來帶去笨重又耗體力。交給 Seamew 讓所有訊息回到同一個收件匣，出門只要帶一隻手機即可掌握所有訊息。",
    "compare.before.label": "過去 / Before",
    "compare.before.title": "四支手機、四個收件匣，一條驗證碼找半天",
    "compare.before.desc": "來不及看就被洗版、SIM 卡換來換去、重要訊息漏接——這些是多門號使用者每天都在遇到的事。",
    "compare.unread": "則未讀",
    "compare.after.label": "現在 / With Seamew",
    "compare.after.title1": "所有門號的訊息，",
    "compare.after.title2": "同一個畫面看完。",
    "compare.after.desc": "不論訊息來自哪個 SIM 卡，都會即時匯流到 Seamew 後台。不用切手機、不用換卡。",
    "compare.row1.msg": "驗證碼 482931",
    "compare.row1.time": "剛剛",
    "compare.row2.msg": "訂單 #2847 已出貨",
    "compare.row3.msg": "完成扣款 NT$ 168",
    "compare.row4.msg": "司機已抵達",

    // Total Solution
    "ts.eyebrow": "Total Solution",
    "ts.title1": "從硬體到通知，",
    "ts.title2": "一條龍由我們交付。",
    "ts.desc.before": "不需要拼湊不同廠商的設備與服務。Seamew 提供 ",
    "ts.desc.hw": "4G/5G SIM 卡 Gateway",
    "ts.desc.mid": "、",
    "ts.desc.cloud": "雲端管理後台",
    "ts.desc.and": "，以及 ",
    "ts.desc.notify": "Telegram / Web 即時通知",
    "ts.desc.after": "——家中插上電、連上 WiFi,剩下的我們都做完了。",
    "ts.sim.label": "SIM 卡",
    "ts.sim.desc": "你的多張門號 SIM 卡",
    "ts.sim.meta": "×N 張 · 任意電信",
    "ts.gw.badge": "Seamew 提供",
    "ts.gw.label": "4G / 5G Gateway",
    "ts.gw.desc": "小巧硬體,家中插電即用",
    "ts.gw.meta": "WiFi · 低功耗",
    "ts.cloud.label": "Seamew Cloud",
    "ts.cloud.desc": "即時匯流、儲存、分流",
    "ts.cloud.meta": "99.9% Uptime",
    "ts.link.insert": "插入",
    "ts.link.wifi": "WiFi 上傳",
    "ts.link.route": "分流推送",
    "ts.tg.label": "Telegram Bot",
    "ts.tg.sub": "即時推播",
    "ts.tg.code": "驗證碼",
    "ts.web.label": "Web 管理後台",
    "ts.web.sub": "瀏覽器登入",
    "ts.web.row1": "OTP 482931",
    "ts.web.row2": "蝦皮已出貨",
    "ts.value1.title": "硬體免採購",
    "ts.value1.desc": "Gateway 由 Seamew 提供，不用研究規格、不用整合不同設備。",
    "ts.value2.title": "家中即可運作",
    "ts.value2.desc": "插電 + 連 WiFi 即可，不需專業網路工程設定。",
    "ts.value3.title": "雙通道接收",
    "ts.value3.desc": "Telegram 即時推播 + Web 後台查閱，怎麼方便就怎麼看。",

    // Features
    "feat.eyebrow": "特色",
    "feat.title1": "專注做好一件事:",
    "feat.title2": "把每一封簡訊穩穩送到你眼前。",
    "feat.f1.title": "即時收件 ‹ 3秒",
    "feat.f1.desc": "訊息一旦進入 4G 模組，立刻同步到後台與手機通知，OTP 驗證碼絕不延遲。",
    "feat.f2.title": "多門號統一管理",
    "feat.f2.desc": "一個帳號可綁定無上限門號，依用途、依用戶、依分組任意切換檢視。",
    "feat.f3.title": "全新線上管理後台",
    "feat.f3.desc": "瀏覽器即可登入，桌機、平板、手機 RWD 全支援。Gateway 與模組狀態一目了然。",
    "feat.f4.title": "穩定 99.9% 服務",
    "feat.f4.desc": "獨立 Gateway 架構，斷網自動重連、訊息不漏接。為長期使用設計。",
    "feat.f1.tickerMsg1": "驗證碼 482931",
    "feat.f1.tickerMsg2": "訂單 #2847 已出貨",
    "feat.f2.more": "+ 4 more",

    // Console
    "console.eyebrow": "線上管理後台",
    "console.title1": "全新 Web 後台，",
    "console.title2": "桌機與手機都好用。",
    "console.desc": "不用安裝、不用設定，登入即用。Gateway 連線狀態、模組訊號、每一封簡訊都能即時掌握。",

    // Telegram
    "tg.eyebrow": "Telegram 整合 · 新功能",
    "tg.title1": "訊息抵達 Seamew，",
    "tg.title2": "同步飛進你的 Telegram",
    "tg.desc": "綁定 Telegram Bot，所有門號收到的簡訊會即時推送到你的對話框。無需打開後台、無需開 App，OTP 驗證碼直接在你最常用的訊息軟體裡看到。",
    "tg.bullet1.t": "個人 Chat 或 群組",
    "tg.bullet1.d": "把 Bot 拉進群組，團隊一起收到通知",
    "tg.bullet2.t": "每個門號獨立對話",
    "tg.bullet2.d": "不同 SIM 卡可推到不同 chat ID 分流",
    "tg.bullet3.t": "OTP 自動高亮",
    "tg.bullet3.d": "系統偵測驗證碼格式，一鍵複製貼上",
    "tg.bullet4.t": "關鍵字過濾",
    "tg.bullet4.d": "可設定哪些簡訊推 TG、哪些只留後台",
    "tg.flow1": "SIM 收到訊息",
    "tg.flow2": "Seamew 處理",
    "tg.flow3": "推送到 Telegram",
    "tg.bot.name": "Seamew SMS Bot",
    "tg.bot.status": "線上 · 4 個門號已連接",
    "tg.day": "今天",
    "tg.input": "Message",
    "tg.from1": "中華電信",
    "tg.body1.before": "您的驗證碼為 ",
    "tg.body1.after": "，請於 5 分鐘內輸入。",
    "tg.from2": "蝦皮購物",
    "tg.body2": "您的訂單 #2847 已出貨，預計明日送達。物流追蹤:spe.tw/...",
    "tg.from3": "Line Pay",
    "tg.body3": "完成扣款 NT$ 168，餘額 NT$ 2,350。",
    "tg.from4": "Uber",
    "tg.body4": "司機已抵達。車牌 ABC-1234，黑色 Toyota。",

    // Who
    "who.eyebrow": "誰適合用",
    "who.title1": "為個人 & 小團隊而生，",
    "who.title2": "不為大公司而設計。",
    "who.c1.role": "For 01 / 個人",
    "who.c1.title": "多 SIM 卡的省錢小資族",
    "who.c1.desc": "電信優惠、副號、雙卡雙待——擁有多張 SIM 卡的人，需要一個地方統一收訊息。",
    "who.c1.tag1": "主號 + 副號",
    "who.c1.tag2": "電信優惠",
    "who.c1.tag3": "副卡管理",
    "who.c2.role": "For 02 / 開發者",
    "who.c2.title": "個人開發者 & Maker",
    "who.c2.desc": "開發 App 需要 OTP 簡訊測試？公司多人共用幾組測試門號，需要手機借來借去？",
    "who.c2.tag1": "OTP 測試",
    "who.c2.tag2": "多帳號管理",
    "who.c2.tag3": "公司帳號共享",
    "who.c3.role": "For 03 / 小團隊",
    "who.c3.title": "需要多門號的遊戲工作室",
    "who.c3.desc": "登入多個遊戲帳號，傳遞虛擬寶物，交易點數物品。",
    "who.c3.tag1": "多人協作",
    "who.c3.tag2": "權限管理",
    "who.c3.tag3": "操作紀錄",

    // CTA
    "cta.eyebrow": "讓所有裝置都能安穩連線",
    "cta.title1": "讓 Seamew 幫你",
    "cta.title2": "送達每一封簡訊。",
    "cta.desc": "把 SIM 卡插上 Seamew 4G Gateway，剩下的交給 Seamew 幫你處理。",
    "cta.btn1": "了解更多 →",
    "cta.btn2": "聯繫我們",

    // Footer
    "foot.tos": "服務條款",
    "foot.privacy": "隱私政策",
    "foot.contact": "聯繫我們",
    "foot.copy": "© 2025 Seamew · Your SMS Postman.",

    // Dashboard mockup
    "mw.brand.sub": "SMS Console",
    "mw.nav.modules": "設備模組",
    "mw.nav.inbox": "簡訊收件匣",
    "mw.nav.smsTest": "SMS 發送測試",
    "mw.nav.devices": "導流管理",
    "mw.nav.accounts": "帳號管理",
    "mw.nav.settings": "系統設定",
    "mw.user.role": "系統管理員",
    "mw.crumb.dash": "儀表板",
    "mw.crumb.modules": "設備模組",
    "mw.search": "搜尋 Module ID…",
    "mw.gw.status": "連線中",
    "mw.gw.firmware": "韌體 1.0.10",
    "mw.gw.signal": "訊號",
    "mw.gw.signalVal": "優良",
    "mw.gw.paired": "已配對門號",
    "mw.gw.todayMsgs": "今日訊息",
    "mw.gw.lastSeen": "最後活躍",
    "mw.gw.lastSeenVal": "21 秒前",
    "mw.tbl.title": "4G 模組",
    "mw.tbl.tabAll": "全部",
    "mw.tbl.tabOnline": "在線 4",
    "mw.tbl.tabOffline": "離線 0",
    "mw.tbl.col.num": "門號",
    "mw.tbl.col.id": "Module ID",
    "mw.tbl.col.gw": "Gateway",
    "mw.tbl.col.sig": "訊號",
    "mw.tbl.col.msgs": "今日訊息",
    "mw.tbl.col.time": "最後更新",
    "mw.tbl.time1": "12 秒前",
    "mw.tbl.time2": "44 秒前",
    "mw.tbl.time3": "1 分前",
    "mw.tbl.time4": "2 分前",
    "mw.page.eyebrow": "概覽",
    "mw.page.title": "設備模組",
    "mw.page.refresh": "重新整理",
    "mw.page.add": "新增模組",
    "mw.phone.title": "收件匣",
    "mw.phone.sub": "4 個門號 · 全部即時同步",
    "mw.phone.tabAll": "全部 12",
    "mw.phone.tabUnread": "未讀 3",
    "mw.phone.tabOTP": "OTP",
    "mw.phone.from1": "中華電信",
    "mw.phone.msg1": "您的驗證碼為 482931，請於 5 分鐘內…",
    "mw.phone.time1": "剛剛",
    "mw.phone.from2": "蝦皮購物",
    "mw.phone.msg2": "您的訂單 #2847 已出貨，預計明日…",
    "mw.phone.from3": "Line Pay",
    "mw.phone.msg3": "完成扣款 NT$ 168，餘額 NT$ 2,350",
    "mw.phone.from4": "Uber",
    "mw.phone.msg4": "司機已抵達。車牌 ABC-1234",
    "mw.phone.from5": "MyCard",
    "mw.phone.msg5": "點數儲值成功 ⋯",
    "mw.phone.time5": "昨天",
  },

  en: {
    "nav.why": "Why Seamew",
    "nav.solution": "Solution",
    "nav.features": "Features",
    "nav.console": "Web Console",
    "nav.telegram": "Telegram",
    "nav.who": "For Whom",
    "nav.learn": "Learn More",

    "hero.eyebrow": "v2 · Web Console is now live",
    "hero.title1": "Your",
    "hero.titleSMS": "SMS",
    "hero.title2": "Postman.",
    "hero.sub.before": "A ",
    "hero.sub.strong": "unified SMS inbox",
    "hero.sub.after": " for everyone juggling multiple phone numbers. One account, one screen — every message arrives in real time.",
    "hero.cta.learn": "Learn More",
    "hero.cta.demo": "See the Console",
    "hero.meta.numbers": "Max.32",
    "hero.meta.numbersLbl": "Numbers / Gateway",
    "hero.meta.delay": "< 3s",
    "hero.meta.delayLbl": "Delivery Latency",
    "hero.meta.uptimeLbl": "Service Uptime",
    "hero.meta.saving": "Hardware Saving",
    "hero.meta.savingLbl": "10K+ in savings",
    "hero.bubble1.from": "Chunghwa · 0987-***-321",
    "hero.bubble1.body": "OTP",
    "hero.bubble2.from": "Shopee · 0912-***-815",
    "hero.bubble2.body": "Order",
    "hero.bubble2.body2": "shipped",
    "hero.bubble3.from": "LINE PAY · 0939-***-777",
    "hero.bubble3.body": "Charged",

    "compare.eyebrow": "Pain / Fix",
    "compare.title1": "If you carry multiple SIMs,",
    "compare.title2": "you know the pain.",
    "compare.desc": "SIM cards scattered across phones and slots; vital OTPs always somewhere else; phones that go flat from being shuffled around. Seamew funnels every message into one inbox so you only need to carry the phone in your pocket.",
    "compare.before.label": "Before",
    "compare.before.title": "Four phones, four inboxes, one OTP nowhere to be found.",
    "compare.before.desc": "Buried by spam, swapping SIMs, missing critical messages — daily life with multiple numbers.",
    "compare.unread": "unread",
    "compare.after.label": "With Seamew",
    "compare.after.title1": "Every number's messages,",
    "compare.after.title2": "in one place.",
    "compare.after.desc": "Whichever SIM receives the SMS, it streams into Seamew instantly. No swapping phones. No swapping cards.",
    "compare.row1.msg": "OTP 482931",
    "compare.row1.time": "now",
    "compare.row2.msg": "Order #2847 shipped",
    "compare.row3.msg": "Charged NT$ 168",
    "compare.row4.msg": "Driver has arrived",

    "ts.eyebrow": "Total Solution",
    "ts.title1": "From hardware to notifications,",
    "ts.title2": "we deliver the whole stack.",
    "ts.desc.before": "No more stitching together vendors. Seamew ships the ",
    "ts.desc.hw": "4G/5G SIM Gateway",
    "ts.desc.mid": ", the ",
    "ts.desc.cloud": "cloud console",
    "ts.desc.and": ", and ",
    "ts.desc.notify": "real-time Telegram & Web alerts",
    "ts.desc.after": " — plug it in at home, connect Wi-Fi, and we handle the rest.",
    "ts.sim.label": "SIM Cards",
    "ts.sim.desc": "Your multiple SIM cards",
    "ts.sim.meta": "×N · any carrier",
    "ts.gw.badge": "Provided by Seamew",
    "ts.gw.label": "4G / 5G Gateway",
    "ts.gw.desc": "Compact hardware, plug-and-play",
    "ts.gw.meta": "Wi-Fi · low-power",
    "ts.cloud.label": "Seamew Cloud",
    "ts.cloud.desc": "Realtime ingest, storage, routing",
    "ts.cloud.meta": "99.9% Uptime",
    "ts.link.insert": "insert",
    "ts.link.wifi": "Wi-Fi upload",
    "ts.link.route": "route",
    "ts.tg.label": "Telegram Bot",
    "ts.tg.sub": "Live push",
    "ts.tg.code": "OTP",
    "ts.web.label": "Web Console",
    "ts.web.sub": "Browser login",
    "ts.web.row1": "OTP 482931",
    "ts.web.row2": "Shopee shipped",
    "ts.value1.title": "No hardware sourcing",
    "ts.value1.desc": "We ship the Gateway. No spec hunting, no vendor stitching.",
    "ts.value2.title": "Runs from home",
    "ts.value2.desc": "Power + Wi-Fi is all you need. No network engineering required.",
    "ts.value3.title": "Two delivery channels",
    "ts.value3.desc": "Telegram push + Web console — whichever way you prefer.",

    "feat.eyebrow": "Features",
    "feat.title1": "We focus on one thing:",
    "feat.title2": "every SMS, delivered to you.",
    "feat.f1.title": "Live delivery, ‹ 3s",
    "feat.f1.desc": "The instant the 4G module receives an SMS, it lands in your console and on your phone. OTPs never lag.",
    "feat.f2.title": "All numbers, one console",
    "feat.f2.desc": "Bind unlimited numbers to one account. Filter by purpose, owner, or group at will.",
    "feat.f3.title": "Brand-new web console",
    "feat.f3.desc": "Log in from any browser. Desktop, tablet, mobile — fully responsive. Gateway and module health at a glance.",
    "feat.f4.title": "99.9% rock-solid",
    "feat.f4.desc": "Independent Gateway architecture, auto-reconnect, no message loss. Built for the long run.",
    "feat.f1.tickerMsg1": "OTP 482931",
    "feat.f1.tickerMsg2": "Order #2847 shipped",
    "feat.f2.more": "+ 4 more",

    "console.eyebrow": "Web Console",
    "console.title1": "A polished web console,",
    "console.title2": "great on desktop and mobile.",
    "console.desc": "No install, no setup — log in and go. Gateway status, module signal, every message at your fingertips.",

    "tg.eyebrow": "Telegram Integration · New",
    "tg.title1": "From Seamew, ",
    "tg.title2": "straight into your Telegram",
    "tg.desc": "Bind a Telegram bot and every SMS pushes into your chat in real time. No console, no app — OTPs land where you already are.",
    "tg.bullet1.t": "1-on-1 or group chat",
    "tg.bullet1.d": "Add the bot to a group; the whole team gets the alert.",
    "tg.bullet2.t": "Per-number routing",
    "tg.bullet2.d": "Push different SIMs to different chat IDs.",
    "tg.bullet3.t": "Auto-highlighted OTPs",
    "tg.bullet3.d": "We detect codes and make them one-tap copyable.",
    "tg.bullet4.t": "Keyword filtering",
    "tg.bullet4.d": "Choose what gets pushed and what stays in the console.",
    "tg.flow1": "SIM receives SMS",
    "tg.flow2": "Seamew processes",
    "tg.flow3": "Push to Telegram",
    "tg.bot.name": "Seamew SMS Bot",
    "tg.bot.status": "Online · 4 numbers connected",
    "tg.day": "Today",
    "tg.input": "Message",
    "tg.from1": "Chunghwa Telecom",
    "tg.body1.before": "Your verification code is ",
    "tg.body1.after": ". It expires in 5 minutes.",
    "tg.from2": "Shopee",
    "tg.body2": "Order #2847 shipped, arriving tomorrow. Track: spe.tw/...",
    "tg.from3": "Line Pay",
    "tg.body3": "Charged NT$ 168. Balance NT$ 2,350.",
    "tg.from4": "Uber",
    "tg.body4": "Your driver has arrived. ABC-1234, black Toyota.",

    "who.eyebrow": "Who it's for",
    "who.title1": "Built for individuals & small teams,",
    "who.title2": "not enterprises.",
    "who.c1.role": "For 01 / Individuals",
    "who.c1.title": "Budget-savvy multi-SIM users",
    "who.c1.desc": "Carrier deals, secondary lines, dual-SIM phones — anyone with multiple SIMs needs one place for all messages.",
    "who.c1.tag1": "Primary + Secondary",
    "who.c1.tag2": "Carrier Deals",
    "who.c1.tag3": "Sub-SIM Mgmt",
    "who.c2.role": "For 02 / Developers",
    "who.c2.title": "Indie devs & makers",
    "who.c2.desc": "Need OTP testing? Sharing test numbers across the team? No more passing handsets around.",
    "who.c2.tag1": "OTP Testing",
    "who.c2.tag2": "Multi-Account",
    "who.c2.tag3": "Team Sharing",
    "who.c3.role": "For 03 / Small Teams",
    "who.c3.title": "Game studios with multiple accounts",
    "who.c3.desc": "Log into multiple game accounts, transfer items, trade points seamlessly.",
    "who.c3.tag1": "Collaboration",
    "who.c3.tag2": "Permissions",
    "who.c3.tag3": "Audit Log",

    "cta.eyebrow": "Reliable connectivity for every device",
    "cta.title1": "Let Seamew deliver",
    "cta.title2": "every single SMS.",
    "cta.desc": "Slot your SIMs into the Seamew 4G Gateway and we'll take care of the rest.",
    "cta.btn1": "Learn More →",
    "cta.btn2": "Contact Us",

    "foot.tos": "Terms",
    "foot.privacy": "Privacy",
    "foot.contact": "Contact",
    "foot.copy": "© 2025 Seamew · Your SMS Postman.",

    // Dashboard mockup
    "mw.brand.sub": "SMS Console",
    "mw.nav.modules": "Modules",
    "mw.nav.inbox": "Inbox",
    "mw.nav.smsTest": "SMS Test",
    "mw.nav.devices": "Routing",
    "mw.nav.accounts": "Accounts",
    "mw.nav.settings": "Settings",
    "mw.user.role": "Administrator",
    "mw.crumb.dash": "Dashboard",
    "mw.crumb.modules": "Modules",
    "mw.search": "Search Module ID…",
    "mw.gw.status": "Online",
    "mw.gw.firmware": "Firmware 1.0.10",
    "mw.gw.signal": "Signal",
    "mw.gw.signalVal": "Excellent",
    "mw.gw.paired": "Paired numbers",
    "mw.gw.todayMsgs": "Messages today",
    "mw.gw.lastSeen": "Last seen",
    "mw.gw.lastSeenVal": "21s ago",
    "mw.tbl.title": "4G Modules",
    "mw.tbl.tabAll": "All",
    "mw.tbl.tabOnline": "Online 4",
    "mw.tbl.tabOffline": "Offline 0",
    "mw.tbl.col.num": "Number",
    "mw.tbl.col.id": "Module ID",
    "mw.tbl.col.gw": "Gateway",
    "mw.tbl.col.sig": "Signal",
    "mw.tbl.col.msgs": "Today",
    "mw.tbl.col.time": "Last update",
    "mw.tbl.time1": "12s ago",
    "mw.tbl.time2": "44s ago",
    "mw.tbl.time3": "1m ago",
    "mw.tbl.time4": "2m ago",
    "mw.page.eyebrow": "Overview",
    "mw.page.title": "Modules",
    "mw.page.refresh": "Refresh",
    "mw.page.add": "Add Module",
    "mw.phone.title": "Inbox",
    "mw.phone.sub": "4 numbers · live sync",
    "mw.phone.tabAll": "All 12",
    "mw.phone.tabUnread": "Unread 3",
    "mw.phone.tabOTP": "OTP",
    "mw.phone.from1": "Chunghwa",
    "mw.phone.msg1": "Your verification code is 482931, valid for 5 min…",
    "mw.phone.time1": "now",
    "mw.phone.from2": "Shopee",
    "mw.phone.msg2": "Order #2847 has shipped, arriving tomorrow…",
    "mw.phone.from3": "Line Pay",
    "mw.phone.msg3": "Charged NT$ 168, balance NT$ 2,350",
    "mw.phone.from4": "Uber",
    "mw.phone.msg4": "Driver has arrived. Plate ABC-1234",
    "mw.phone.from5": "MyCard",
    "mw.phone.msg5": "Top-up successful ⋯",
    "mw.phone.time5": "Yesterday",
  },
};

// Detect browser language
function detectLang() {
  try {
    const stored = localStorage.getItem("seamew-lang");
    if (stored === "zh" || stored === "en") return stored;
  } catch (e) {}
  const lang = (navigator.language || navigator.userLanguage || "en").toLowerCase();
  return lang.startsWith("zh") ? "zh" : "en";
}

// Global state + listeners
let CURRENT_LANG = detectLang();
const listeners = new Set();

function setLang(l) {
  CURRENT_LANG = l;
  try { localStorage.setItem("seamew-lang", l); } catch (e) {}
  document.documentElement.lang = l === "zh" ? "zh-Hant" : "en";
  listeners.forEach((fn) => fn(l));
}

// Hook
function useLang() {
  const [, force] = React.useState(0);
  React.useEffect(() => {
    const fn = () => force((x) => x + 1);
    listeners.add(fn);
    return () => listeners.delete(fn);
  }, []);
  const t = (key) => {
    const dict = TRANSLATIONS[CURRENT_LANG] || TRANSLATIONS.en;
    return dict[key] || TRANSLATIONS.en[key] || key;
  };
  return { lang: CURRENT_LANG, setLang, t };
}

// Initialise <html lang> on first load
document.documentElement.lang = CURRENT_LANG === "zh" ? "zh-Hant" : "en";

window.useLang = useLang;
window.SeamewSetLang = setLang;
