/* global React */
// ============================================================
// i18n — 中英双精细化（Sprint 2.L 收尾，2026-05-10）
// 英文是认真本土化版本（不是机翻），目标让老外读着像 The Verge / Vox 写的文章
// ============================================================
const STRINGS = {
	zh: {
		"app.tagline": "熊猫头工坊",
		"nav.quick": "快速生图",
		"nav.collection": "合集",        // 用户：删"我的"二字
		"nav.story": "故事",
		"lang.toggle": "中/EN",

		"quick.title": "快速生图",
		"quick.subtitle": "选几个零件，立刻得到一张能发出去的表情。",
		"quick.copy": "复制",
		"quick.download": "下载",
		"quick.fav": "收藏",
		"quick.copied": "已复制到剪贴板",
		"quick.saved": "已收藏",
		"quick.unsaved": "已取消收藏",
		"quick.text": "文字",
		"quick.text.placeholder": "敲点字…",
		"quick.font": "字体",
		"quick.random": "随机生图",
		"quick.random.text": "随机文字",
		"quick.name.placeholder": "给它起个名字…",
		"quick.name.save": "存到合集",
		"quick.lang.both": "双语",
		"quick.lang.zh": "中文",
		"quick.lang.en": "English",

		"col.title": "合集",
		"col.subtitle": "贴在墙上的表情手账。",
		"col.filter.all": "全部",
		"col.filter.recent": "最近收藏",
		"col.filter.section": "按板块筛选",
		"col.selected": "已选 {n}",
		"col.action.all": "全选",
		"col.action.none": "取消选择",
		"col.action.zip": "批量打包 ZIP",
		"col.action.tg": "导出为 Telegram 表情包",
		"col.action.wx": "导出为微信表情包",
		"col.action.delete": "删除",
		"col.guide": "导出指南",
		"col.empty.title": "合集是空的",
		"col.empty.body": "去「快速生图」捏一只熊猫头，点 ♥ 收藏，TA 就会贴在这面墙上。",
		"col.empty.cta": "去生图",
		"col.guide.tg.cta": "一键打包并跳转 Telegram",
		"col.rename": "改名",
		"col.rename.placeholder": "起个名字…",

		// 故事板（中文版 — 用户提供考据精炼）
		"story.eyebrow": "一座小博物馆",
		"story.title": "熊猫头：大众化的 Meme 王者",
		"story.subtitle": "一张图，记录了中文互联网二十年的情绪与狂欢。",
		"story.timeline": "时间线",
		"story.credits": "致谢与版权说明",
		"story.credits.body": "致谢「熊猫头」原型来源——埃及芝士广告与韩国演员崔成国（金馆长）的笑容，以及多年来 PS 这一形象的所有网友。本页所有素材出于研究、教育与合理使用目的呈现，不用于商业用途。",

		"kbd.tip": "快捷键",
		"kbd.r": "随机",
		"kbd.c": "复制",
		"kbd.d": "下载",

		"ui.popover.skip": "Esc 跳过",
		"ui.popover.save": "保存",
	},
	en: {
		"app.tagline": "panda head, in 60 seconds",
		"nav.quick": "Generator",
		"nav.collection": "Saved",
		"nav.story": "Story",
		"lang.toggle": "中/EN",

		"quick.title": "Quick Generator",
		"quick.subtitle": "Pick the parts. Get a sendable panda. That's it.",
		"quick.copy": "Copy",
		"quick.download": "Download",
		"quick.fav": "Save",
		"quick.copied": "Copied to clipboard",
		"quick.saved": "Saved",
		"quick.unsaved": "Removed",
		"quick.text": "Text",
		"quick.text.placeholder": "Type something…",
		"quick.font": "Font",
		"quick.random": "Random",
		"quick.random.text": "Random text",
		"quick.name.placeholder": "Give it a name…",
		"quick.name.save": "Save to collection",
		"quick.lang.both": "Both",
		"quick.lang.zh": "Chinese",
		"quick.lang.en": "English",

		"col.title": "Saved",
		"col.subtitle": "Your scrapbook wall.",
		"col.filter.all": "All",
		"col.filter.recent": "Recent",
		"col.filter.section": "By section",
		"col.selected": "{n} selected",
		"col.action.all": "Select all",
		"col.action.none": "Clear",
		"col.action.zip": "Pack as ZIP",
		"col.action.tg": "Export to Telegram",
		"col.action.wx": "Export to WeChat",
		"col.action.delete": "Delete",
		"col.guide": "How to export",
		"col.empty.title": "Nothing saved yet",
		"col.empty.body": "Head to Generator, make a panda, hit ♥, and it'll show up on this wall.",
		"col.empty.cta": "Open Generator",
		"col.guide.tg.cta": "Pack & open Telegram",
		"col.rename": "Rename",
		"col.rename.placeholder": "Name it…",

		// Story (本土化英文 — 不是机翻；调子模仿 The Verge / Vox 的文化报道)
		"story.eyebrow": "A small museum",
		"story.title": "Panda Head: China's Universal Meme",
		"story.subtitle": "One blurry face, two decades of Chinese internet feelings.",
		"story.timeline": "Timeline",
		"story.credits": "Credits & fair use",
		"story.credits.body": "Credits to the Egyptian cheese commercial and Korean actor Choi Sung-kook (the source of the original face), plus the countless anonymous Photoshoppers who carried this panda into culture. All assets are presented under research / educational fair use.",

		"kbd.tip": "Shortcuts",
		"kbd.r": "Random",
		"kbd.c": "Copy",
		"kbd.d": "Download",

		"ui.popover.skip": "Esc to skip",
		"ui.popover.save": "Save",
	},
};

const I18nContext = React.createContext({ lang: "zh", t: (k) => k });

const I18nProvider = ({ children }) => {
	const [lang, setLang] = React.useState(() => {
		// 默认 en（用户：首次载入英文版）
		try { return localStorage.getItem("pk-lang") || "en"; } catch { return "en"; }
	});
	React.useEffect(() => {
		try { localStorage.setItem("pk-lang", lang); } catch {}
	}, [lang]);
	const t = React.useCallback(
		(key, vars) => {
			let s = (STRINGS[lang] && STRINGS[lang][key]) || STRINGS.zh[key] || key;
			if (vars) for (const k in vars) s = s.replace(`{${k}}`, vars[k]);
			return s;
		},
		[lang]
	);
	return (
		<I18nContext.Provider value={{ lang, setLang, t }}>
			{children}
		</I18nContext.Provider>
	);
};

const useI18n = () => React.useContext(I18nContext);

window.I18nProvider = I18nProvider;
window.useI18n = useI18n;
