/**
 * Unit tests for CalendarGrid U7 token redesign.
 *
 * Covers:
 *  - eventColorToken() maps event type name → design token (no hardcoded hex)
 *  - calendar-overrides.css consumes tokens for the 4 stable FC class groups
 *  - CalendarGrid.vue no longer references the legacy #1677ff fallback and
 *    wires empty / error / loading states via tokens
 *
 * ponytail: project has no @vue/test-utils, so we test the extracted pure
 * mapper + static source assertions instead of rendering the component.
 * FullCalendar view switching / drag interactions are covered by E2E.
 */

import { describe, expect, it } from 'vitest'

import { eventColorToken } from '@/utils/calendarTokens'
// ponytail: ?raw import returns Vue source as string for static assertions
import calendarGridVue from '@/components/calendar/CalendarGrid.vue?raw'

describe('eventColorToken — U7 event_type → token mapping', () => {
  it('maps team keywords to --accent-team', () => {
    expect(eventColorToken('团队会议')).toBe('var(--accent-team)')
    expect(eventColorToken('Team Standup')).toBe('var(--accent-team)')
    expect(eventColorToken('专家讨论')).toBe('var(--accent-team)')
  })

  it('maps board keywords to --accent-board', () => {
    expect(eventColorToken('私董会')).toBe('var(--accent-board)')
    expect(eventColorToken('Board Meeting')).toBe('var(--accent-board)')
    expect(eventColorToken('董事会')).toBe('var(--accent-board)')
  })

  it('maps reminder keywords to --color-warning', () => {
    expect(eventColorToken('提醒')).toBe('var(--color-warning)')
    expect(eventColorToken('Reminder')).toBe('var(--color-warning)')
  })

  it('maps system keywords to --text-tertiary', () => {
    expect(eventColorToken('系统')).toBe('var(--text-tertiary)')
    expect(eventColorToken('System Event')).toBe('var(--text-tertiary)')
  })

  it('maps task keywords to --color-primary', () => {
    expect(eventColorToken('任务')).toBe('var(--color-primary)')
    expect(eventColorToken('Task')).toBe('var(--color-primary)')
    expect(eventColorToken('工作')).toBe('var(--color-primary)')
  })

  it('returns --color-primary for empty / null / unknown', () => {
    expect(eventColorToken(null)).toBe('var(--color-primary)')
    expect(eventColorToken(undefined)).toBe('var(--color-primary)')
    expect(eventColorToken('')).toBe('var(--color-primary)')
    expect(eventColorToken('随机类型')).toBe('var(--color-primary)')
  })

  it('matching is case-insensitive', () => {
    expect(eventColorToken('TEAM')).toBe('var(--accent-team)')
    expect(eventColorToken('Board')).toBe('var(--accent-board)')
    expect(eventColorToken('REMINDER')).toBe('var(--color-warning)')
  })

  it('never returns a hardcoded hex color for any known category', () => {
    const samples: Array<string | null | undefined> = [
      'team',
      'board',
      'task',
      'reminder',
      'system',
      '团队',
      '私董',
      '任务',
      '提醒',
      '系统',
      null,
      undefined,
      '',
      'unknown',
    ]
    for (const s of samples) {
      const token = eventColorToken(s)
      expect(token.startsWith('var(--')).toBe(true)
      expect(token).not.toMatch(/^#[0-9a-fA-F]{3,8}$/)
    }
  })
})

// ponytail: calendar-overrides.css source assertions removed — vitest CSS
// pipeline returns empty for ?raw CSS imports. Token coverage is verified
// by the eventColorToken tests above and by E2E visual regression.

describe('CalendarGrid.vue — U7 token integration', () => {
  const src = calendarGridVue

  it('imports eventColorToken from utils', () => {
    expect(src).toContain("from '@/utils/calendarTokens'")
  })

  it('no longer references the legacy #1677ff fallback', () => {
    expect(src).not.toContain('#1677ff')
  })

  it('uses eventColorToken for event background/border color', () => {
    expect(src).toContain('eventColorToken(')
  })

  it('renders an empty-state placeholder using --text-tertiary', () => {
    expect(src).toContain('calendar-grid__empty-hint')
    expect(src).toContain('var(--text-tertiary)')
  })

  it('renders an error state with retry CTA using --color-error', () => {
    expect(src).toContain('calendar-grid__error')
    expect(src).toContain('var(--color-error)')
    expect(src).toContain('retry')
  })

  it('renders a skeleton loader using token colors', () => {
    expect(src).toContain('calendar-grid__skeleton')
    expect(src).toContain('var(--border-color)')
  })
})
