import { Announcement, Calendar, Parish } from '@/payload-types'

type AnnouncementLink = {
  id: string
  text: string
  href: string
}

type PerParishEntry = {
  parish: Parish
  doc: Announcement | Calendar
}

export const perParish = (data: PerParishEntry[]) => {
  const links: AnnouncementLink[] = []

  for (const { parish, doc } of data) {
    if (typeof doc.document === 'string') continue

    links.push({
      id: parish.id,
      text: parish.name,
      href: doc.document.url || 'undefined',
    })
  }

  return links
}
