import { Worship } from '@/payload-types'
import { EventRowProps } from '@/components/EventRow/EventRow'

/**
 * Transform the worship category to a readable string
 */
export const transformCategory = (category: "MASS" | "FAMILY" | "WORD" | "LANGUAGE" | "OTHER"): string => {
  const type = {
    'MASS': 'Eucharistiefeier',
    'FAMILY': 'Familiengottesdienst',
    'WORD': 'Wort-Gottes-Feier',
    'LANGUAGE': 'Eucharistiefeier in Fremdsprache',
    'OTHER': 'Gottesdienst',
  }

  return type[category] ?? 'Gottesdienst'
}

/**
 * Transform worship data to `EventRow` component properties
 */
export const tranformWorship = (worship: Worship[]): (EventRowProps & {id: string})[] => {

  return worship.map(w => {
    return {
      id: w.id,
      title: typeof w.title === "string" && w.title.length > 0 ? w.title : transformCategory(w.type),
      date: w.date,
      href: `/gottesdienst/${w.id}`,
      location: typeof w.location === 'string' ? w.location : w.location.name,
      cancelled: w.cancelled,
    }
  })
}