/**
 * 统一的标签映射工具
 * 用于课程包的年级标签和领域标签的中英文转换
 */

// 年级标签映射（英文 → 中文）
export const GRADE_TAG_MAP: Record<string, string> = {
  // 大写格式
  SMALL: "小班",
  MIDDLE: "中班",
  BIG: "大班",
  // 小写格式
  small: "小班",
  middle: "中班",
  big: "大班",
};

// 领域标签映射（英文 → 中文）- 导出供其他模块使用
export const DOMAIN_TAG_MAP: Record<string, string> = {
  // 旧格式（大写）
  LANGUAGE: "语言",
  SCIENCE: "科学",
  SOCIAL: "社会",
  ART: "艺术",
  HEALTH: "健康",
  MATH: "数学",

  // 课程环节/领域 DOMAIN_ 前缀格式（后端返回）
  DOMAIN_HEALTH: "健康",
  DOMAIN_LANGUAGE: "语言",
  DOMAIN_SOCIAL: "社会",
  DOMAIN_SCIENCE: "科学",
  DOMAIN_ART: "艺术",

  // 活动类型作为领域的兼容映射（历史数据兼容）
  family: "亲子活动",
  FAMILY: "亲子活动",
  class: "课堂活动",
  CLASS: "课堂活动",
  outdoor: "户外活动",
  OUTDOOR: "户外活动",
  handicraft: "手工活动",
  HANDICRAFT: "手工活动",
  game: "游戏活动",
  GAME: "游戏活动",
  music: "音乐活动",
  MUSIC: "音乐活动",
  exploration: "探索活动",
  EXPLORATION: "探索活动",
  sports: "运动活动",
  SPORTS: "运动活动",
  art: "艺术活动",

  // 新格式（细分领域）
  // 健康领域
  health_motor: "身体动作发展",
  health_hygiene: "生活习惯与能力",
  HEALTH_MOTOR: "身体动作发展",
  HEALTH_HYGIENE: "生活习惯与能力",

  // 语言领域
  lang_listen: "倾听与表达",
  lang_read: "早期阅读",
  LANG_LISTEN: "倾听与表达",
  LANG_READ: "早期阅读",
  language_communication: "语言",
  LANGUAGE_COMMUNICATION: "语言",

  // 社会领域
  social_interact: "人际交往",
  social_adapt: "社会适应",
  SOCIAL_INTERACT: "人际交往",
  SOCIAL_ADAPT: "社会适应",
  social_emotional: "社会",
  SOCIAL_EMOTIONAL: "社会",

  // 科学领域
  science_explore: "科学探究",
  math_cog: "数学认知",
  SCIENCE_EXPLORE: "科学探究",
  MATH_COG: "数学认知",
  science_exploration: "科学",
  SCIENCE_EXPLORATION: "科学",

  // 艺术领域
  art_music: "音乐表现",
  art_create: "美术创作",
  ART_MUSIC: "音乐表现",
  ART_CREATE: "美术创作",
  art_creativity: "艺术",
  ART_CREATIVITY: "艺术",
};

// 年级标签颜色配置
export const GRADE_TAG_COLORS: Record<string, { bg: string; text: string }> = {
  小班: { bg: "#FFE4E8", text: "#E85A71" },
  中班: { bg: "#E3F2FD", text: "#1976D2" },
  大班: { bg: "#FFF8E1", text: "#F9A825" },
};

// 领域标签颜色配置
export const DOMAIN_TAG_COLORS: Record<string, { bg: string; text: string }> = {
  语言: { bg: "#F3E5F5", text: "#8E24AA" },
  倾听与表达: { bg: "#F3E5F5", text: "#8E24AA" },
  早期阅读: { bg: "#EDE7F6", text: "#7B1FA2" },

  科学: { bg: "#E8F5E9", text: "#43A047" },
  科学探究: { bg: "#E8F5E9", text: "#43A047" },
  数学认知: { bg: "#F1F8E9", text: "#558B2F" },

  社会: { bg: "#E0F7FA", text: "#0097A7" },
  人际交往: { bg: "#E0F7FA", text: "#0097A7" },
  社会适应: { bg: "#E0F2F1", text: "#00695C" },

  艺术: { bg: "#FFF3E0", text: "#FB8C00" },
  音乐表现: { bg: "#FFF3E0", text: "#FB8C00" },
  美术创作: { bg: "#FBE9E7", text: "#E64A19" },

  健康: { bg: "#FFEBEE", text: "#E53935" },
  身体动作发展: { bg: "#FFEBEE", text: "#E53935" },
  生活习惯与能力: { bg: "#FFCDD2", text: "#C62828" },

  数学: { bg: "#FFF8E1", text: "#F9A825" },
};

// ==================== 课程环节类型映射（与课程列表 tag 一致） ====================

export const LESSON_TYPE_NAMES: Record<string, string> = {
  INTRODUCTION: "导入课",
  INTRO: "导入课",
  COLLECTIVE: "集体课",
  LANGUAGE: "语言",
  HEALTH: "健康",
  SCIENCE: "科学",
  SOCIAL: "社会",
  ART: "艺术",
  DOMAIN_HEALTH: "健康",
  DOMAIN_LANGUAGE: "语言",
  DOMAIN_SOCIAL: "社会",
  DOMAIN_SCIENCE: "科学",
  DOMAIN_ART: "艺术",
};

export const LESSON_TYPE_COLORS: Record<string, { bg: string; text: string }> = {
  INTRODUCTION: { bg: "#E8F5E9", text: "#2E7D32" },
  INTRO: { bg: "#E8F5E9", text: "#2E7D32" },
  COLLECTIVE: { bg: "#E3F2FD", text: "#1565C0" },
  LANGUAGE: { bg: "#F3E5F5", text: "#7B1FA2" },
  HEALTH: { bg: "#FFEBEE", text: "#C62828" },
  SCIENCE: { bg: "#E8F5E9", text: "#388E3C" },
  SOCIAL: { bg: "#E0F7FA", text: "#00838F" },
  ART: { bg: "#FFF3E0", text: "#E65100" },
  DOMAIN_HEALTH: { bg: "#FFEBEE", text: "#C62828" },
  DOMAIN_LANGUAGE: { bg: "#F3E5F5", text: "#7B1FA2" },
  DOMAIN_SOCIAL: { bg: "#E0F7FA", text: "#00838F" },
  DOMAIN_SCIENCE: { bg: "#E8F5E9", text: "#388E3C" },
  DOMAIN_ART: { bg: "#FFF3E0", text: "#E65100" },
};

/**
 * 获取课程环节类型的中文名称
 */
export function getLessonTypeName(type: string): string {
  return LESSON_TYPE_NAMES[type] || type;
}

/**
 * 获取课程环节类型标签样式（与课程卡片 tag 一致）
 */
export function getLessonTagStyle(type: string): {
  background: string;
  color: string;
  border: string;
} {
  const colors = LESSON_TYPE_COLORS[type] || { bg: "#F5F5F5", text: "#666" };
  return {
    background: colors.bg,
    color: colors.text,
    border: "none",
  };
}

// ==================== 年级/领域 ====================

/**
 * 转换年级标签为中文
 */
export function translateGradeTag(tag: string): string {
  return GRADE_TAG_MAP[tag] || tag;
}

/**
 * 转换领域标签为中文
 */
export function translateDomainTag(tag: string): string {
  return DOMAIN_TAG_MAP[tag] || tag;
}

/**
 * 批量转换年级标签
 */
export function translateGradeTags(tags: string[]): string[] {
  return (tags || []).map(translateGradeTag);
}

/**
 * 批量转换领域标签
 */
export function translateDomainTags(tags: string[]): string[] {
  return (tags || []).map(translateDomainTag);
}

/**
 * 获取年级标签样式
 */
export function getGradeTagStyle(tag: string): {
  background: string;
  color: string;
  border: string;
} {
  const colors = GRADE_TAG_COLORS[tag] || { bg: "#F0F0F0", text: "#666" };
  return {
    background: colors.bg,
    color: colors.text,
    border: "none",
  };
}

/**
 * 获取领域标签样式
 */
export function getDomainTagStyle(tag: string): {
  background: string;
  color: string;
  border: string;
} {
  const colors = DOMAIN_TAG_COLORS[tag] || { bg: "#F0F0F0", text: "#666" };
  return {
    background: colors.bg,
    color: colors.text,
    border: "none",
  };
}

// ==================== 活动相关映射 ====================

// 活动类型映射（英文 → 中文）
export const ACTIVITY_TYPE_MAP: Record<string, string> = {
  // 大写格式
  HANDICRAFT: "手工活动",
  GAME: "游戏活动",
  MUSIC: "音乐活动",
  EXPLORATION: "探索活动",
  SPORTS: "运动活动",
  OUTDOOR: "户外活动",
  FAMILY: "家庭延伸",
  ART: "美工活动",
  OTHER: "其他",

  // 小写格式
  handicraft: "手工活动",
  game: "游戏活动",
  music: "音乐活动",
  exploration: "探索活动",
  sports: "运动活动",
  outdoor: "户外活动",
  family: "家庭延伸",
  art: "美工活动",
  other: "其他",

  // 其他格式
  class: "课堂活动",
};

// 活动类型颜色配置
export const ACTIVITY_TYPE_COLORS: Record<
  string,
  { bg: string; text: string }
> = {
  手工活动: { bg: "#F3E5F5", text: "#8E24AA" },
  美工活动: { bg: "#F3E5F5", text: "#8E24AA" },
  游戏活动: { bg: "#FFF3E0", text: "#FB8C00" },
  音乐活动: { bg: "#E3F2FD", text: "#1976D2" },
  运动活动: { bg: "#E8F5E9", text: "#43A047" },
  探索活动: { bg: "#E0F7FA", text: "#0097A7" },
  户外活动: { bg: "#F1F8E9", text: "#558B2F" },
  亲子活动: { bg: "#FCE4EC", text: "#C2185B" },
  家庭延伸: { bg: "#E3F2FD", text: "#1976D2" },
  课堂活动: { bg: "#FFF8E1", text: "#F9A825" },
  艺术活动: { bg: "#FBE9E7", text: "#E64A19" },
  其他: { bg: "#F5F5F5", text: "#666666" },
};

/**
 * 转换活动类型为中文
 */
export function translateActivityType(type: string): string {
  return ACTIVITY_TYPE_MAP[type] || type;
}

/**
 * 获取活动类型样式
 */
export function getActivityTypeStyle(type: string): {
  background: string;
  color: string;
  border: string;
} {
  const colors = ACTIVITY_TYPE_COLORS[type] || { bg: "#F0F0F0", text: "#666" };
  return {
    background: colors.bg,
    color: colors.text,
    border: "none",
  };
}

/**
 * 转换活动领域为中文（使用领域标签映射）
 */
export function translateActivityDomain(domain: string): string {
  return DOMAIN_TAG_MAP[domain] || domain;
}

// ==================== 教学流程步骤类型映射 ====================

// 步骤类型映射（英文 → 中文）
export const STEP_TYPE_MAP: Record<string, string> = {
  // 大写格式
  TEACHING: "教学",
  READING: "共读",
  DISCUSSION: "讨论",
  ACTIVITY: "活动",
  GAME: "游戏",
  SUMMARY: "总结",
  WARMUP: "热身",
  PRACTICE: "练习",
  INTERACTION: "互动",
  // 新增环节类型
  INTRODUCTION: "导入",
  CREATIVE: "创作",
  CUSTOM: "自定义",

  // 小写格式
  teaching: "教学",
  reading: "共读",
  discussion: "讨论",
  activity: "活动",
  game: "游戏",
  summary: "总结",
  warmup: "热身",
  practice: "练习",
  interaction: "互动",
  introduction: "导入",
  creative: "创作",
  custom: "自定义",
};

// 步骤类型颜色配置
export const STEP_TYPE_COLORS: Record<string, { bg: string; text: string }> = {
  教学: { bg: "#E3F2FD", text: "#1976D2" },
  共读: { bg: "#F3E5F5", text: "#8E24AA" },
  阅读: { bg: "#F3E5F5", text: "#8E24AA" },
  讨论: { bg: "#E0F7FA", text: "#0097A7" },
  活动: { bg: "#FFF3E0", text: "#FB8C00" },
  游戏: { bg: "#FCE4EC", text: "#C2185B" },
  总结: { bg: "#E8F5E9", text: "#43A047" },
  热身: { bg: "#FFF8E1", text: "#F9A825" },
  练习: { bg: "#EDE7F6", text: "#673AB7" },
  互动: { bg: "#FBE9E7", text: "#E64A19" },
  导入: { bg: "#E8F5E9", text: "#4CAF50" },
  创作: { bg: "#FCE4EC", text: "#E91E63" },
  自定义: { bg: "#ECEFF1", text: "#607D8B" },
};

/**
 * 转换步骤类型为中文
 */
export function translateStepType(type: string): string {
  return STEP_TYPE_MAP[type] || type;
}

/**
 * 获取步骤类型样式
 */
export function getStepTypeStyle(type: string): {
  background: string;
  color: string;
  border: string;
} {
  const colors = STEP_TYPE_COLORS[type] || { bg: "#F0F0F0", text: "#666" };
  return {
    background: colors.bg,
    color: colors.text,
    border: "none",
  };
}

// ==================== 课程状态映射 ====================

// 课程状态映射（英文 → 中文）
export const COURSE_STATUS_MAP: Record<string, string> = {
  DRAFT: "草稿",
  UNSUBMITTED: "未提交",
  PENDING: "审核中",
  APPROVED: "已通过",
  REJECTED: "已驳回",
  PUBLISHED: "已发布",
  ARCHIVED: "已下架",
  REVIEWING: "审核中",

  // 小写格式
  draft: "草稿",
  pending: "审核中",
  approved: "已通过",
  rejected: "已驳回",
  published: "已发布",
  archived: "已下架",
  reviewing: "审核中",
};

// 课程状态颜色配置
export const COURSE_STATUS_COLORS: Record<
  string,
  { bg: string; text: string }
> = {
  草稿: { bg: "#F5F5F5", text: "#666666" },
  未提交: { bg: "#E8EAF6", text: "#5C6BC0" },
  审核中: { bg: "#E3F2FD", text: "#1976D2" },
  已驳回: { bg: "#FFEBEE", text: "#E53935" },
  已通过:{ bg: "#E8F5E9", text: "#43A047" },
  已发布: { bg: "#E8F5E9", text: "#43A047" },
  已下架: { bg: "#FFF8E1", text: "#F9A825" },
};

/**
 * 转换课程状态为中文
 */
export function translateCourseStatus(status: string): string {
  return COURSE_STATUS_MAP[status] || status;
}

/**
 * 获取课程状态样式
 */
export function getCourseStatusStyle(status: string): {
  background: string;
  color: string;
  border: string;
} {
  const chineseStatus = COURSE_STATUS_MAP[status] || status;
  const colors = COURSE_STATUS_COLORS[chineseStatus] || {
    bg: "#F0F0F0",
    text: "#666",
  };
  return {
    background: colors.bg,
    color: colors.text,
    border: "none",
  };
}

// ==================== 资源类型映射 ====================

// 资源类型映射
export const RESOURCE_TYPE_MAP: Record<string, string> = {
  EBOOK: "电子绘本",
  AUDIO: "音频",
  VIDEO: "视频",
  PPT: "PPT课件",
  POSTER: "教学挂图",
  OTHER: "其他资源",
  IMAGE: "图片",

  // 已中文的不转换
  电子绘本: "电子绘本",
  音频: "音频",
  视频: "视频",
  PPT课件: "PPT课件",
  教学挂图: "教学挂图",
  其他资源: "其他资源",
  图片: "图片",
};

/**
 * 转换资源类型为中文
 */
export function translateResourceType(type: string): string {
  return RESOURCE_TYPE_MAP[type] || type;
}

// ==================== 通用状态映射 ====================

// 通用状态映射（用于 Student、Teacher、Parent、Class 等实体的 active/ACTIVE 状态）
export const GENERIC_STATUS_MAP: Record<string, string> = {
  ACTIVE: "启用",
  active: "启用",
  INACTIVE: "停用",
  inactive: "停用",
  ARCHIVED: "归档",
  archived: "归档",
};

// 通用状态颜色配置
export const GENERIC_STATUS_COLORS: Record<
  string,
  { bg: string; text: string }
> = {
  启用: { bg: "#E8F5E9", text: "#43A047" },
  停用: { bg: "#F5F5F5", text: "#9E9E9E" },
  归档: { bg: "#FFF8E1", text: "#F9A825" },
};

/**
 * 转换通用状态为中文
 */
export function translateGenericStatus(status: string): string {
  return GENERIC_STATUS_MAP[status] || status;
}

/**
 * 获取通用状态样式
 */
export function getGenericStatusStyle(status: string): {
  background: string;
  color: string;
  border: string;
} {
  const chineseStatus = GENERIC_STATUS_MAP[status] || status;
  const colors = GENERIC_STATUS_COLORS[chineseStatus] || {
    bg: "#F0F0F0",
    text: "#666",
  };
  return {
    background: colors.bg,
    color: colors.text,
    border: "none",
  };
}

// ==================== 任务完成状态映射 ====================

// 任务完成状态映射
export const TASK_COMPLETION_STATUS_MAP: Record<string, string> = {
  PENDING: "待提交",
  SUBMITTED: "已提交",
  REVIEWED: "已评价",
  COMPLETED: "已完成",
  completed: "已完成", // 兼容旧数据
  IN_PROGRESS: "进行中",
  in_progress: "进行中",
};

// 任务完成状态颜色配置
export const TASK_COMPLETION_STATUS_COLORS: Record<
  string,
  { bg: string; text: string }
> = {
  待提交: { bg: "#FFF8E1", text: "#F9A825" },
  已提交: { bg: "#E3F2FD", text: "#1976D2" },
  已评价: { bg: "#E8F5E9", text: "#43A047" },
  已完成: { bg: "#E8F5E9", text: "#2E7D32" },
  进行中: { bg: "#E0F7FA", text: "#0097A7" },
};

/**
 * 转换任务完成状态为中文
 */
export function translateTaskCompletionStatus(status: string): string {
  return TASK_COMPLETION_STATUS_MAP[status] || status;
}

/**
 * 获取任务完成状态样式
 */
export function getTaskCompletionStatusStyle(status: string): {
  background: string;
  color: string;
  border: string;
} {
  const chineseStatus = TASK_COMPLETION_STATUS_MAP[status] || status;
  const colors = TASK_COMPLETION_STATUS_COLORS[chineseStatus] || {
    bg: "#F0F0F0",
    text: "#666",
  };
  return {
    background: colors.bg,
    color: colors.text,
    border: "none",
  };
}

// ==================== 通知类型映射 ====================

// 通知类型映射
export const NOTIFICATION_TYPE_MAP: Record<string, string> = {
  SYSTEM: "系统通知",
  TASK: "任务通知",
  SCHEDULE: "日程通知",
  COURSE: "课程通知",
};

// 通知类型颜色配置
export const NOTIFICATION_TYPE_COLORS: Record<
  string,
  { bg: string; text: string }
> = {
  系统通知: { bg: "#F3E5F5", text: "#8E24AA" },
  任务通知: { bg: "#E3F2FD", text: "#1976D2" },
  日程通知: { bg: "#E0F7FA", text: "#0097A7" },
  课程通知: { bg: "#FFF8E1", text: "#F9A825" },
};

/**
 * 转换通知类型为中文
 */
export function translateNotificationType(type: string): string {
  return NOTIFICATION_TYPE_MAP[type] || type;
}

/**
 * 获取通知类型样式
 */
export function getNotificationTypeStyle(type: string): {
  background: string;
  color: string;
  border: string;
} {
  const chineseType = NOTIFICATION_TYPE_MAP[type] || type;
  const colors = NOTIFICATION_TYPE_COLORS[chineseType] || {
    bg: "#F0F0F0",
    text: "#666",
  };
  return {
    background: colors.bg,
    color: colors.text,
    border: "none",
  };
}

// ==================== 通知接收者类型映射 ====================

// 通知接收者类型映射
export const NOTIFICATION_RECIPIENT_TYPE_MAP: Record<string, string> = {
  ALL: "所有人",
  TEACHER: "教师",
  SCHOOL: "学校管理员",
  PARENT: "家长",
  STUDENT: "学生",
};

// 通知接收者类型颜色配置
export const NOTIFICATION_RECIPIENT_TYPE_COLORS: Record<
  string,
  { bg: string; text: string }
> = {
  所有人: { bg: "#E8F5E9", text: "#43A047" },
  教师: { bg: "#E3F2FD", text: "#1976D2" },
  学校管理员: { bg: "#FFF8E1", text: "#F9A825" },
  家长: { bg: "#FCE4EC", text: "#C2185B" },
  学生: { bg: "#E0F7FA", text: "#0097A7" },
};

/**
 * 转换通知接收者类型为中文
 */
export function translateNotificationRecipientType(type: string): string {
  return NOTIFICATION_RECIPIENT_TYPE_MAP[type] || type;
}

/**
 * 获取通知接收者类型样式
 */
export function getNotificationRecipientTypeStyle(type: string): {
  background: string;
  color: string;
  border: string;
} {
  const chineseType = NOTIFICATION_RECIPIENT_TYPE_MAP[type] || type;
  const colors = NOTIFICATION_RECIPIENT_TYPE_COLORS[chineseType] || {
    bg: "#F0F0F0",
    text: "#666",
  };
  return {
    background: colors.bg,
    color: colors.text,
    border: "none",
  };
}

// ==================== 日程来源类型映射 ====================

// 日程来源类型映射
export const SCHEDULE_SOURCE_TYPE_MAP: Record<string, string> = {
  TEACHER: "教师创建",
  SCHOOL: "学校创建",
};

// 日程来源类型颜色配置
export const SCHEDULE_SOURCE_TYPE_COLORS: Record<
  string,
  { bg: string; text: string }
> = {
  教师创建: { bg: "#F3E5F5", text: "#8E24AA" },
  学校创建: { bg: "#E3F2FD", text: "#1976D2" },
};

/**
 * 转换日程来源类型为中文
 */
export function translateScheduleSourceType(type: string): string {
  return SCHEDULE_SOURCE_TYPE_MAP[type] || type;
}

/**
 * 获取日程来源类型样式
 */
export function getScheduleSourceTypeStyle(type: string): {
  background: string;
  color: string;
  border: string;
} {
  const chineseType = SCHEDULE_SOURCE_TYPE_MAP[type] || type;
  const colors = SCHEDULE_SOURCE_TYPE_COLORS[chineseType] || {
    bg: "#F0F0F0",
    text: "#666",
  };
  return {
    background: colors.bg,
    color: colors.text,
    border: "none",
  };
}

// ==================== 租户状态映射 ====================

// 租户状态映射（用于 Tenant 实体的状态）
export const TENANT_STATUS_MAP: Record<string, string> = {
  ACTIVE: "正常",
  SUSPENDED: "暂停",
  EXPIRED: "过期",
};

// 租户状态颜色配置
export const TENANT_STATUS_COLORS: Record<
  string,
  { bg: string; text: string }
> = {
  正常: { bg: "#E8F5E9", text: "#43A047" },
  暂停: { bg: "#FFF8E1", text: "#F9A825" },
  过期: { bg: "#F5F5F5", text: "#9E9E9E" },
};

/**
 * 转换租户状态为中文
 */
export function translateTenantStatus(status: string): string {
  return TENANT_STATUS_MAP[status] || status;
}

/**
 * 获取租户状态样式
 */
export function getTenantStatusStyle(status: string): {
  background: string;
  color: string;
  border: string;
} {
  const chineseStatus = TENANT_STATUS_MAP[status] || status;
  const colors = TENANT_STATUS_COLORS[chineseStatus] || {
    bg: "#F0F0F0",
    text: "#666",
  };
  return {
    background: colors.bg,
    color: colors.text,
    border: "none",
  };
}

// ==================== 用户角色映射 ====================

// 用户角色映射（与后端 UserRole 枚举对应）
export const USER_ROLE_MAP: Record<string, string> = {
  ADMIN: "超级管理员",
  SCHOOL: "学校管理员",
  TEACHER: "教师",
  PARENT: "家长",
};

// 用户角色颜色配置
export const USER_ROLE_COLORS: Record<string, { bg: string; text: string }> = {
  超级管理员: { bg: "#E8F5E9", text: "#2E7D32" },
  学校管理员: { bg: "#E3F2FD", text: "#1565C0" },
  教师: { bg: "#F3E5F5", text: "#7B1FA2" },
  家长: { bg: "#FFF8E1", text: "#F9A825" },
};

/**
 * 转换用户角色为中文
 */
export function translateUserRole(role: string): string {
  return USER_ROLE_MAP[role] || role;
}

/**
 * 获取用户角色样式
 */
export function getUserRoleStyle(role: string): {
  background: string;
  color: string;
  border: string;
} {
  const chineseRole = USER_ROLE_MAP[role] || role;
  const colors = USER_ROLE_COLORS[chineseRole] || {
    bg: "#F0F0F0",
    text: "#666",
  };
  return {
    background: colors.bg,
    color: colors.text,
    border: "none",
  };
}

const THEME_HEX = /^#[0-9A-Fa-f]{6}$/;

function themeHexToRgb(hex: string): [number, number, number] {
  const h = hex.startsWith("#") ? hex : `#${hex}`;
  if (!THEME_HEX.test(h)) {
    return [89, 89, 89];
  }
  return [
    parseInt(h.slice(1, 3), 16),
    parseInt(h.slice(3, 5), 16),
    parseInt(h.slice(5, 7), 16),
  ];
}

/**
 * 课程主题 Tag 样式（与主题字典中配置的颜色一致，浅底 + 主题色文字/描边）
 */
export function getThemeTagStyle(themeColor?: string | null): {
  background: string;
  color: string;
  border: string;
} {
  const raw = (themeColor || "").trim();
  const hex = raw.startsWith("#") ? raw : raw ? `#${raw}` : "";
  if (!hex || !THEME_HEX.test(hex)) {
    return {
      background: "#fafafa",
      color: "#595959",
      border: "1px solid #d9d9d9",
    };
  }
  const [r, g, b] = themeHexToRgb(hex);
  return {
    background: `rgba(${r},${g},${b},0.12)`,
    color: hex,
    border: `1px solid rgba(${r},${g},${b},0.35)`,
  };
}
