import rawWords from '@content/palabras-globales.json'
import type { GlobalWord, GlobalWordWithSlug } from '../types/content'
import { slugify } from '../utils/slug'

export const globalWords = (rawWords as GlobalWordWithSlug[]).map((word) => ({
  ...word,
  slug: slugify(word.palabra),
}))

export const wordThemes = Array.from(
  globalWords.reduce<Map<string, GlobalWord[]>>((acc, word) => {
    const bucket = acc.get(word.tema) ?? []
    bucket.push(word)
    acc.set(word.tema, bucket)
    return acc
  }, new Map())
).map(([tema, palabras]) => ({ tema, palabras }))

export const highlightWords = globalWords.slice(0, 6)
