/**
 * 轻量 i18n（contract §1.7 命名空间：admin.* / iam.error.* / bff.error.* / gateway.error.* / network.error.*）
 *
 * 维护者：ai16
 * 仲裁：F4 i18n key 模式 error.{{service}}.{{code_snake_case}}
 */

type MessageMap = Record<string, string>;

const messages: MessageMap = {
  // 导航
  "admin.nav.dashboard": "管理仪表盘",
  "admin.nav.users": "用户管理",
  "admin.nav.roles": "角色权限",
  "admin.nav.permissions": "权限点",
  "admin.nav.viewports": "视口配置",
  "admin.nav.organization": "组织管理",
  "admin.nav.system": "学校设置",
  "admin.nav.classes": "班级管理",
  "admin.nav.teachers": "教师管理",
  "admin.nav.students": "学生管理",
  "admin.nav.auditLogs": "审计日志",

  // 通用
  "admin.common.search": "搜索",
  "admin.common.filter": "筛选",
  "admin.common.create": "新建",
  "admin.common.edit": "编辑",
  "admin.common.delete": "删除",
  "admin.common.save": "保存",
  "admin.common.cancel": "取消",
  "admin.common.confirm": "确认",
  "admin.common.export": "导出",
  "admin.common.actions": "操作",
  "admin.common.status": "状态",
  "admin.common.all": "全部",
  "admin.common.loading": "加载中...",
  "admin.common.empty": "暂无数据",
  "admin.common.error": "加载失败",
  "admin.common.retry": "重试",
  "admin.common.page": "页",
  "admin.common.total": "共",
  "admin.common.records": "条",
  "admin.common.active": "启用",
  "admin.common.disabled": "禁用",
  "admin.common.locked": "锁定",
  "admin.common.yes": "是",
  "admin.common.no": "否",
  "admin.common.name": "姓名",
  "admin.common.email": "邮箱",
  "admin.common.role": "角色",
  "admin.common.createdAt": "创建时间",
  "admin.common.updatedAt": "更新时间",
  "admin.common.lastLoginAt": "最后登录",
  "admin.common.dataScope": "数据范围",
  "admin.common.school": "学校",
  "admin.common.grade": "年级",
  "admin.common.class": "班级",

  // 仪表盘
  "admin.dashboard.title": "管理仪表盘",
  "admin.dashboard.totalTeachers": "教师总数",
  "admin.dashboard.totalStudents": "学生总数",
  "admin.dashboard.totalClasses": "班级总数",
  "admin.dashboard.totalSchools": "学校总数",
  "admin.dashboard.schoolAvgScore": "全校平均分",
  "admin.dashboard.activeUsersToday": "今日活跃用户",
  "admin.dashboard.auditEventsToday": "今日审计事件",
  "admin.dashboard.trend": "趋势",
  "admin.dashboard.serviceHealth": "服务健康",

  // 用户管理
  "admin.users.title": "用户管理",
  "admin.users.new": "新建用户",
  "admin.users.edit": "编辑用户",
  "admin.users.deleteConfirm": "确认删除该用户？",
  "admin.users.toggleStatus": "切换状态",
  "admin.users.assignRole": "分配角色",
  "admin.users.password": "密码",
  "admin.users.roles": "角色",
  "admin.users.organization": "所属组织",

  // 角色权限
  "admin.roles.title": "角色权限管理",
  "admin.roles.new": "新建角色",
  "admin.roles.permissionMatrix": "权限矩阵",
  "admin.roles.systemRole": "系统预置",
  "admin.roles.userCount": "用户数",
  "admin.roles.deleteConfirm": "确认删除该角色？",
  "admin.roles.cannotDeleteSystem": "系统预置角色不可删除",
  "admin.roles.cannotDeleteWithUsers": "角色下仍有用户，不可删除",

  // 权限点
  "admin.permissions.title": "权限点管理",
  "admin.permissions.resource": "资源",
  "admin.permissions.action": "操作",
  "admin.permissions.code": "权限码",

  // 视口配置
  "admin.viewports.title": "视口配置",
  "admin.viewports.key": "标识",
  "admin.viewports.label": "标签",
  "admin.viewports.route": "路由",
  "admin.viewports.sortOrder": "排序",
  "admin.viewports.requiredPermission": "所需权限",
  "admin.viewports.scope": "作用域",
  "admin.viewports.visible": "是否可见",
  "admin.viewports.dragHint": "拖拽调整排序",

  // 组织管理
  "admin.organization.title": "组织管理",
  "admin.organization.school": "学校",
  "admin.organization.expand": "展开",
  "admin.organization.collapse": "折叠",

  // 学校设置
  "admin.system.title": "学校设置",
  "admin.system.schoolName": "学校名称",
  "admin.system.schoolCode": "学校代码",
  "admin.system.academicYear": "学年",
  "admin.system.semester": "学期",
  "admin.system.contactEmail": "联系邮箱",
  "admin.system.contactPhone": "联系电话",
  "admin.system.address": "地址",
  "admin.system.timezone": "时区",
  "admin.system.locale": "语言",
  "admin.system.saveSuccess": "设置已保存",

  // 班级管理
  "admin.classes.title": "班级管理",
  "admin.classes.headTeacher": "班主任",
  "admin.classes.studentCount": "学生数",

  // 教师管理
  "admin.teachers.title": "教师管理",
  "admin.teachers.subjects": "任教科目",
  "admin.teachers.classCount": "班级数",

  // 学生管理
  "admin.students.title": "学生管理",
  "admin.students.guardian": "家长",
  "admin.students.guardianPhone": "家长电话",

  // 审计日志
  "admin.auditLogs.title": "审计日志",
  "admin.auditLogs.actor": "操作人",
  "admin.auditLogs.action": "操作",
  "admin.auditLogs.resource": "资源",
  "admin.auditLogs.resourceId": "资源ID",
  "admin.auditLogs.ip": "IP地址",
  "admin.auditLogs.time": "时间",
  "admin.auditLogs.dateRange": "时间范围",
  "admin.auditLogs.exportCsv": "导出CSV",
  "admin.auditLogs.traceId": "追踪ID",

  // 通知
  "admin.notification.title": "通知中心",
  "admin.notification.auditAlert": "审计告警",
  "admin.notification.abnormalLogin": "异常登录",
  "admin.notification.systemError": "系统异常",

  // 退出
  "admin.auth.logout": "退出登录",
  "admin.auth.welcome": "Edu 管理端",

  // 学校管理（细化）
  "admin.school.title": "学校管理",
  "admin.school.schools": "学校列表",
  "admin.school.grades": "年级管理",
  "admin.school.departments": "部门管理",
  "admin.school.academicYear": "学年学期",
  "admin.school.gradeInsights": "年级洞察",
  "admin.school.principal": "校长",
  "admin.school.director": "年级主任",
  "admin.school.leader": "负责人",
  "admin.school.memberCount": "成员数",
  "admin.school.subject": "学科",
  "admin.school.startDate": "开始日期",
  "admin.school.endDate": "结束日期",
  "admin.school.currentYear": "当前学年",
  "admin.school.insights.summary": "全校概览",
  "admin.school.insights.homework": "作业时间线",
  "admin.school.insights.rankings": "班级排名",
  "admin.school.insights.avgScore": "平均分",
  "admin.school.insights.passingRate": "及格率",
  "admin.school.insights.rank": "排名",
  "admin.school.insights.delta": "环比",

  // 审计日志子模块
  "admin.auditLogs.overview": "审计总览",
  "admin.auditLogs.dataChanges": "数据变更",
  "admin.auditLogs.loginLogs": "登录日志",
  "admin.auditLogs.totalEvents": "总事件数",
  "admin.auditLogs.todayEvents": "今日事件",
  "admin.auditLogs.uniqueActors": "操作人数",
  "admin.auditLogs.failedActions": "失败操作",
  "admin.auditLogs.topActions": "热门操作",
  "admin.auditLogs.topResources": "热门资源",
  "admin.auditLogs.trend": "操作趋势",
  "admin.auditLogs.tableName": "数据表",
  "admin.auditLogs.recordId": "记录ID",
  "admin.auditLogs.beforeState": "变更前",
  "admin.auditLogs.afterState": "变更后",
  "admin.auditLogs.loginAction": "登录动作",
  "admin.auditLogs.loginStatus": "状态",
  "admin.auditLogs.failureReason": "失败原因",
  "admin.auditLogs.userAgent": "User-Agent",

  // 公告管理
  "admin.announcements.title": "公告管理",
  "admin.announcements.new": "发布公告",
  "admin.announcements.publish": "发布",
  "admin.announcements.archive": "归档",
  "admin.announcements.pin": "置顶",
  "admin.announcements.unpin": "取消置顶",
  "admin.announcements.draft": "草稿",
  "admin.announcements.published": "已发布",
  "admin.announcements.archived": "已归档",
  "admin.announcements.audience": "受众",
  "admin.announcements.readCount": "已读",
  "admin.announcements.author": "发布人",
  "admin.announcements.publishedAt": "发布时间",

  // 邀请码管理
  "admin.invitationCodes.title": "邀请码管理",
  "admin.invitationCodes.generate": "批量生成",
  "admin.invitationCodes.code": "邀请码",
  "admin.invitationCodes.batch": "批次",
  "admin.invitationCodes.unused": "未使用",
  "admin.invitationCodes.used": "已使用",
  "admin.invitationCodes.expired": "已过期",
  "admin.invitationCodes.bindRole": "绑定角色",
  "admin.invitationCodes.bindClass": "绑定班级",
  "admin.invitationCodes.bindEmail": "限定邮箱",
  "admin.invitationCodes.usedBy": "使用者",
  "admin.invitationCodes.usedAt": "使用时间",
  "admin.invitationCodes.expiresAt": "过期时间",
  "admin.invitationCodes.generateCount": "生成数量",
  "admin.invitationCodes.generateSuccess": "成功生成 {{count}} 个邀请码",

  // 文件管理
  "admin.files.title": "文件管理",
  "admin.files.filename": "文件名",
  "admin.files.mimeType": "类型",
  "admin.files.size": "大小",
  "admin.files.entityType": "关联类型",
  "admin.files.uploadedBy": "上传者",
  "admin.files.totalFiles": "文件总数",
  "admin.files.totalSize": "总大小",
  "admin.files.batchDelete": "批量删除",
  "admin.files.preview": "预览",

  // AI 配置
  "admin.aiSettings.title": "AI 配置",
  "admin.aiSettings.providers": "AI Provider",
  "admin.aiSettings.usage": "用量统计",
  "admin.aiSettings.totalRequests": "总请求数",
  "admin.aiSettings.totalTokens": "总 Token",
  "admin.aiSettings.totalCost": "总费用",
  "admin.aiSettings.provider": "Provider",
  "admin.aiSettings.model": "模型",
  "admin.aiSettings.isActive": "启用",
  "admin.aiSettings.isPublic": "公共",
  "admin.aiSettings.addProvider": "添加 Provider",

  // 系统设置增强
  "admin.system.security": "安全策略",
  "admin.system.fileUpload": "文件上传",
  "admin.system.notification": "通知配置",
  "admin.system.brand": "品牌配置",
  "admin.system.passwordMinLength": "密码最小长度",
  "admin.system.passwordRequireSpecial": "要求特殊字符",
  "admin.system.passwordRequireUppercase": "要求大写字母",
  "admin.system.sessionTimeout": "会话超时(分钟)",
  "admin.system.forcePasswordChange": "强制修改密码",
  "admin.system.maxFileSize": "最大文件大小(MB)",
  "admin.system.allowedTypes": "允许的文件类型",
  "admin.system.notifyNewUser": "新用户通知",
  "admin.system.notifyScheduleChange": "调课通知",
  "admin.system.notifyAnnouncement": "公告通知",
  "admin.system.logoUrl": "Logo URL",
  "admin.system.primaryColor": "主题色",
  "admin.system.schoolMotto": "校训",
};

/**
 * 翻译函数
 * @param key i18n key（如 "admin.nav.dashboard"）
 * @param params 模板参数（如 { count: 5 }，替换 {{count}}）
 */
export function t(
  key: string,
  params?: Record<string, string | number>,
): string {
  let msg = messages[key] ?? key;
  if (params) {
    for (const [k, v] of Object.entries(params)) {
      msg = msg.replace(new RegExp(`\\{\\{${k}\\}\\}`, "g"), String(v));
    }
  }
  return msg;
}
