/**
 * Calendar event-type → design token mapping (U7).
 *
 * ponytail: IEventType.name is user-defined (no backend enum), so we match
 * keywords (CN + EN, case-insensitive) against the 5 semantic categories
 * from the U7 plan. Ceiling: a type named "团队 standby" gets the team token
 * even though "standby" isn't semantic — acceptable, the token is still a
 * sane color. Upgrade path: add an explicit `category` field to IEventType
 * when the backend seeds canonical types.
 *
 * Order matters: the first matching rule wins. `task` is last because its
 * keywords (任务/工作) rarely overlap with the semantic categories above.
 */

const EVENT_TYPE_TOKEN_RULES: ReadonlyArray<readonly [RegExp, string]> = [
  [/(team|团队|专家)/, 'var(--accent-team)'],
  [/(board|私董|董事)/, 'var(--accent-board)'],
  [/(reminder|提醒)/, 'var(--color-warning)'],
  [/(system|系统)/, 'var(--text-tertiary)'],
  [/(task|任务|工作)/, 'var(--color-primary)'],
]

const DEFAULT_EVENT_TOKEN = 'var(--color-primary)'

/**
 * Resolve a calendar event type name to a Notion-style design token.
 * Returns a CSS `var(...)` reference — never a hardcoded hex color.
 */
export function eventColorToken(name: string | null | undefined): string {
  if (!name) return DEFAULT_EVENT_TOKEN
  const lower = name.toLowerCase()
  for (const [re, token] of EVENT_TYPE_TOKEN_RULES) {
    if (re.test(lower)) return token
  }
  return DEFAULT_EVENT_TOKEN
}
