export type Locale = "en" | "zh";

const dict: Record<string, Record<Locale, string>> = {
  // Sidebar
  "sidebar.agentConfig": { en: "Agent Config", zh: "智能体配置" },
  "sidebar.coreFiles": { en: "Core Files", zh: "核心文件" },
  "sidebar.dailyNotes": { en: "Daily Notes", zh: "每日日记" },
  "sidebar.today": { en: "Today", zh: "今日日记" },
  "sidebar.quickAccess": { en: "Quick Access", zh: "快速访问" },
  
  // Skills Page
  "skills.title": { en: "Skills", zh: "技能" },
  "skills.description": { en: "Agent capabilities and extensions", zh: "智能体能力与扩展" },
  "skills.empty": { en: "No skills found", zh: "未找到技能" },
  "sidebar.skills": { en: "Skills", zh: "技能" },
  "sidebar.files": { en: "Files", zh: "文件" },
  "sidebar.search": { en: "Search…", zh: "搜索…" },
  "sidebar.footer": { en: "Silicon Dawn · Memory Viewer", zh: "Silicon Dawn · 记忆查看器" },
  "sidebar.showSensitive": { en: "Show sensitive content", zh: "显示敏感内容" },
  "sidebar.hideSensitive": { en: "Hide sensitive content", zh: "隐藏敏感内容" },
  "sidebar.lightMode": { en: "Switch to light mode", zh: "切换到浅色模式" },
  "sidebar.darkMode": { en: "Switch to dark mode", zh: "切换到深色模式" },

  // Agent Status
  "agent.title": { en: "Agent Status", zh: "智能体状态" },
  "agent.gateway": { en: "Gateway", zh: "网关" },
  "agent.models": { en: "Models", zh: "模型" },
  "agent.heartbeat": { en: "Heartbeat", zh: "心跳" },
  "agent.config": { en: "Safe Config", zh: "安全配置" },
  "agent.running": { en: "Running", zh: "运行中" },
  "agent.stopped": { en: "Stopped", zh: "已停止" },
  "agent.uptime": { en: "uptime", zh: "运行时间" },
  "agent.port": { en: "Port", zh: "端口" },
  "agent.pid": { en: "PID", zh: "PID" },
  "agent.mode": { en: "Mode", zh: "模式" },
  "agent.primary": { en: "Primary Model", zh: "主模型" },
  "agent.ready": { en: "Ready to inference", zh: "就绪" },
  "agent.lastActivity": { en: "Last activity", zh: "最近活动" },
  "agent.noHeartbeat": { en: "No heartbeat data", zh: "无心跳数据" },
  "agent.channel": { en: "channel", zh: "通道" },
  "agent.loading": { en: "Loading status...", zh: "加载状态..." },
  "agent.error": { en: "Failed to load status. Ensure the server is running on the same machine as the agent.", zh: "加载失败。请确保服务器与 Agent 运行在同一台机器上。" },

  // Dashboard
  "dashboard.title": { en: "Dashboard", zh: "仪表盘" },
  "dashboard.uptime": { en: "Uptime", zh: "运行时间" },
  "dashboard.memory": { en: "Memory", zh: "内存" },
  "dashboard.load": { en: "Load", zh: "负载" },
  "dashboard.files": { en: "Files", zh: "文件" },
  "dashboard.mdTracked": { en: ".md files tracked", zh: "个 .md 文件" },
  "dashboard.todayMemory": { en: "Today's Memory", zh: "今日记忆" },
  "dashboard.viewFull": { en: "View full →", zh: "查看全部 →" },
  "dashboard.noMemoryToday": { en: "No memory entries for today yet.", zh: "今天还没有记忆条目。" },
  "dashboard.recentlyModified": { en: "Recently Modified", zh: "最近修改" },
  "dashboard.memoryByMonth": { en: "Memory by Month", zh: "月度记忆" },
  "dashboard.quickAccess": { en: "Quick Access", zh: "快速访问" },
  "dashboard.loading": { en: "Loading…", zh: "加载中…" },
  "dashboard.noFiles": { en: "No files found.", zh: "未找到文件。" },
  "dashboard.noMemoryFiles": { en: "No memory files found.", zh: "未找到记忆文件。" },
  "dashboard.characters": { en: "characters", zh: "个字符" },
  "dashboard.justNow": { en: "just now", zh: "刚刚" },
  "dashboard.minAgo": { en: "min ago", zh: "分钟前" },
  "dashboard.hAgo": { en: "h ago", zh: "小时前" },
  "dashboard.dAgo": { en: "d ago", zh: "天前" },

  // FileViewer
  "file.edit": { en: "Edit", zh: "编辑" },
  "file.save": { en: "Save", zh: "保存" },
  "file.cancel": { en: "Cancel", zh: "取消" },
  "file.saved": { en: "Saved", zh: "已保存" },
  "file.failedToLoad": { en: "Failed to load", zh: "加载失败" },
  "file.saveFailed": { en: "Save failed", zh: "保存失败" },
  "file.words": { en: "words", zh: "词" },
  "file.discardChanges": { en: "Discard unsaved changes?", zh: "放弃未保存的更改？" },
  "file.reloaded": { en: "Reloaded from server", zh: "已从服务器重新加载" },
  "changelog.title": { en: "Changelog", zh: "更新日志" },
  "changelog.back": { en: "Back", zh: "返回" },
  "sidebar.changelog": { en: "Changelog", zh: "更新日志" },
  "file.conflictTitle": { en: "File Conflict", zh: "文件冲突" },
  "file.conflictDesc": { en: "This file was modified on disk while you were editing. Your changes have not been saved.", zh: "文件在编辑期间被其他程序修改，您的更改尚未保存。" },
  "file.conflictTime": { en: "Modified at", zh: "修改时间" },
  "file.conflictOverwrite": { en: "Overwrite", zh: "覆盖" },
  "file.conflictReload": { en: "Reload", zh: "重新加载" },
  "file.loading": { en: "Loading…", zh: "加载中…" },
  "file.backToTop": { en: "Back to top", zh: "返回顶部" },
  "file.copy": { en: "Copy", zh: "复制" },

  // Search
  "search.placeholder": { en: "Search all memory files…", zh: "搜索所有记忆文件…" },
  "search.noResults": { en: "No results found for", zh: "未找到相关结果：" },
  "search.files": { en: "files", zh: "个文件" },
  "search.matches": { en: "matches", zh: "个匹配" },
  "search.results": { en: "results", zh: "个结果" },
  "settings.title": { en: "Settings", zh: "设置" },
  "settings.embedding.title": { en: "Vector Search", zh: "向量搜索" },
  "settings.embedding.description": { en: "Configure an OpenAI-compatible embedding API for semantic search. Supports OpenAI, DeepSeek, SiliconFlow, Ollama, etc.", zh: "配置 OpenAI 兼容的 Embedding API 进行语义搜索。支持 OpenAI、DeepSeek、SiliconFlow、Ollama 等。" },
  "settings.embedding.model": { en: "Model", zh: "模型" },
  "settings.testConnection": { en: "Test Connection", zh: "测试连接" },
  "settings.testing": { en: "Testing…", zh: "测试中…" },
  "settings.save": { en: "Save", zh: "保存" },
  "settings.saving": { en: "Saving…", zh: "保存中…" },
  "settings.saved": { en: "Saved", zh: "已保存" },
  "settings.saveFailed": { en: "Save failed", zh: "保存失败" },
  "search.modeText": { en: "Text", zh: "文本" },
  "search.modeSemantic": { en: "Semantic", zh: "语义" },
  "search.relevance": { en: "relevance", zh: "相关度" },

  // Connections
  "connections.title": { en: "Connections", zh: "连接管理" },
  "connections.add": { en: "Add", zh: "添加" },
  "connections.addNew": { en: "Add Connection", zh: "添加连接" },
  "connections.edit": { en: "Edit Connection", zh: "编辑连接" },
  "connections.save": { en: "Save", zh: "保存" },
  "connections.cancel": { en: "Cancel", zh: "取消" },
  "connections.refresh": { en: "Refresh", zh: "刷新" },
  "connections.active": { en: "Active", zh: "当前连接" },
  "connections.namePlaceholder": { en: "Name (e.g. Bot 01)", zh: "名称（如 Bot 01）" },
  "connections.urlPlaceholder": { en: "URL (e.g. http://host:8901)", zh: "URL（如 http://host:8901）" },
  "connections.tokenPlaceholder": { en: "Token (optional)", zh: "Token（可选）" },
  "connections.switchBot": { en: "Switch Bot", zh: "切换 Bot" },
  "connections.manage": { en: "Manage", zh: "管理" },
  "connections.modeDirect": { en: "Direct", zh: "直连" },
  "connections.modeGateway": { en: "Gateway", zh: "网关" },
  "connections.gatewayUrl": { en: "Gateway URL", zh: "网关地址" },
  "connections.gatewayUrlPlaceholder": { en: "Gateway URL (e.g. http://host:18789)", zh: "网关地址（如 http://host:18789）" },
  "connections.gatewayToken": { en: "Gateway Token", zh: "网关 Token" },
  "connections.gatewayTokenPlaceholder": { en: "Gateway API Token", zh: "网关 API Token" },
  "connections.mvPort": { en: "MV Port", zh: "MV 端口" },
  "connections.mvPortPlaceholder": { en: "Memory Viewer Port (default 8901)", zh: "Memory Viewer 端口（默认 8901）" },

  // Bootstrap
  "bootstrap.checking": { en: "Checking if Memory Viewer is running…", zh: "正在检测 Memory Viewer 是否运行…" },
  "bootstrap.alreadyRunning": { en: "Memory Viewer is already running! Connection saved.", zh: "Memory Viewer 已在运行！连接已保存。" },
  "bootstrap.notInstalled": { en: "Remote bot doesn't have Memory Viewer installed.", zh: "远程 Bot 未安装 Memory Viewer。" },
  "bootstrap.installPrompt": { en: "Would you like to install it via Gateway API? This will send commands to the remote bot.", zh: "是否通过网关 API 安装？这将向远程 Bot 发送安装指令。" },
  "bootstrap.install": { en: "Install", zh: "安装" },
  "bootstrap.installing": { en: "Installing Memory Viewer via Gateway…", zh: "正在通过网关安装 Memory Viewer…" },
  "bootstrap.botResponse": { en: "Bot Response", zh: "Bot 回复" },
  "bootstrap.verifying": { en: "Verifying installation…", zh: "正在验证安装…" },
  "bootstrap.success": { en: "Memory Viewer installed and connected successfully!", zh: "Memory Viewer 安装成功并已连接！" },
  "bootstrap.failed": { en: "Could not connect after installation. The bot may need more time.", zh: "安装后无法连接。Bot 可能需要更多时间。" },
  "bootstrap.retry": { en: "Retry Verification", zh: "重试验证" },
  "bootstrap.close": { en: "Close", zh: "关闭" },
  "bootstrap.error": { en: "Error", zh: "错误" },
  "bootstrap.done": { en: "Done", zh: "完成" },

  // Heatmap
  "heatmap.activeDays": { en: "active days", zh: "个活跃日" },
  "heatmap.total": { en: "total", zh: "总计" },
  "heatmap.perDay": { en: "/day", zh: "/天" },
  "heatmap.less": { en: "Less", zh: "少" },
  "heatmap.more": { en: "More", zh: "多" },
  "heatmap.noData": { en: "No data", zh: "无数据" },

  // Timeline
  "sidebar.timeline": { en: "Timeline", zh: "时间线" },
  "timeline.title": { en: "Memory Timeline", zh: "记忆时间线" },
  "timeline.loading": { en: "Loading memories…", zh: "正在加载记忆…" },
  "timeline.entries": { en: "entries", zh: "篇日记" },
  "timeline.words": { en: "chars", zh: "字符" },
  "timeline.tags": { en: "tags", zh: "标签" },
  "timeline.filterByTag": { en: "Filter by tag:", zh: "按标签筛选：" },
  "timeline.noResults": { en: "No entries found with this tag", zh: "未找到包含此标签的日记" },
  "timeline.empty": { en: "No memory entries found", zh: "未找到记忆日记" },
  "timeline.chars": { en: "chars", zh: "字" },
  "timeline.months": { en: "months", zh: "个月" },

  // Tags
  "sidebar.tags": { en: "Tags", zh: "标签" },
  "tags.title": { en: "Tags", zh: "标签" },
  "tags.subtitle": { en: "Browse memories by topic", zh: "按主题浏览记忆" },
  "tags.totalTags": { en: "tags", zh: "标签" },
  "tags.totalFiles": { en: "files", zh: "文件" },
  "tags.avgPerTag": { en: "avg", zh: "平均" },
  "tags.popular": { en: "Popular Tags", zh: "热门标签" },
  "tags.clear": { en: "Clear filter", zh: "清除筛选" },
  "tags.showing": { en: "Showing tag:", zh: "显示标签：" },
  "tags.files": { en: "files", zh: "个文件" },
  "tags.tags": { en: "tags", zh: "个标签" },
  "tags.noFiles": { en: "No files found with this tag", zh: "没有找到相关文件" },
  "tags.empty": { en: "No tags yet", zh: "暂无标签" },
  "tags.emptyHint": { en: "Use ## headers or #hashtags in Markdown to create tags", zh: "在 Markdown 中使用 ## 标题 或 #标签 来创建标签" },

  // Settings
  "settings.title": { en: "Settings", zh: "设置" },
  "sidebar.settings": { en: "Settings", zh: "设置" },
  "settings.embedding.title": { en: "Embedding Search", zh: "向量搜索" },
  "settings.embedding.enable": { en: "Enable Embedding Search", zh: "启用向量搜索" },
  "settings.embedding.enableDesc": { en: "Use OpenAI Embeddings API for semantic search", zh: "使用 OpenAI Embeddings API 进行语义搜索" },
  "settings.embedding.apiUrl": { en: "API URL", zh: "API 地址" },
  "settings.embedding.apiUrlDesc": { en: "OpenAI Embeddings API or compatible endpoint", zh: "OpenAI Embeddings API 或兼容的端点" },
  "settings.embedding.apiKey": { en: "API Key", zh: "API 密钥" },
  "settings.embedding.apiKeyDesc": { en: "OpenAI API key (sk-...)", zh: "OpenAI API 密钥 (sk-...)" },
  "settings.embedding.apiKeySet": { en: "API key is set", zh: "API 密钥已设置" },
  "settings.embedding.model": { en: "Model", zh: "模型" },
  "settings.embedding.modelDesc": { en: "Embedding model name, e.g. text-embedding-3-small", zh: "Embedding 模型名称，如 text-embedding-3-small" },
  "settings.embedding.test": { en: "Test Connection", zh: "测试连接" },
  "settings.embedding.testing": { en: "Testing...", zh: "测试中..." },
  "settings.save": { en: "Save Settings", zh: "保存设置" },
  "settings.saving": { en: "Saving...", zh: "保存中..." },

  // Cron
  "sidebar.cron": { en: "Cron Jobs", zh: "定时任务" },
  "cron.title": { en: "Cron Jobs", zh: "定时任务" },
  "cron.subtitle": { en: "Manage scheduled tasks", zh: "管理定时任务" },
  "cron.total": { en: "Total", zh: "总计" },
  "cron.enabled": { en: "Enabled", zh: "已启用" },
  "cron.disabled": { en: "Disabled", zh: "已禁用" },
  "cron.refresh": { en: "Refresh", zh: "刷新" },
  "cron.enable": { en: "Enable", zh: "启用" },
  "cron.disable": { en: "Disable", zh: "禁用" },
  "cron.runNow": { en: "Run Now", zh: "立即运行" },
  "cron.history": { en: "History", zh: "历史" },
  "cron.runHistory": { en: "Run History", zh: "运行历史" },
  "cron.loading": { en: "Loading…", zh: "加载中…" },
  "cron.noRuns": { en: "No run history", zh: "暂无运行记录" },
  "cron.empty": { en: "No cron jobs configured", zh: "暂无定时任务" },
  "cron.justNow": { en: "just now", zh: "刚刚" },
  "cron.soonLabel": { en: "soon", zh: "即将" },
  "cron.minAgo": { en: "m ago", zh: "分钟前" },
  "cron.minLater": { en: "m later", zh: "分钟后" },
  "cron.hAgo": { en: "h ago", zh: "小时前" },
  "cron.hLater": { en: "h later", zh: "小时后" },
  "cron.dAgo": { en: "d ago", zh: "天前" },
  "cron.dLater": { en: "d later", zh: "天后" },

  // Months
  "month.01": { en: "Jan", zh: "1月" },
  "month.02": { en: "Feb", zh: "2月" },
  "month.03": { en: "Mar", zh: "3月" },
  "month.04": { en: "Apr", zh: "4月" },
  "month.05": { en: "May", zh: "5月" },
  "month.06": { en: "Jun", zh: "6月" },
  "month.07": { en: "Jul", zh: "7月" },
  "month.08": { en: "Aug", zh: "8月" },
  "month.09": { en: "Sep", zh: "9月" },
  "month.10": { en: "Oct", zh: "10月" },
  "month.11": { en: "Nov", zh: "11月" },
  "month.12": { en: "Dec", zh: "12月" },
};

export function translate(key: string, locale: Locale): string {
  return dict[key]?.[locale] ?? key;
}
