---
import { getCollection } from 'astro:content'
import Layout from '../../layouts/Layout.astro'
import QuestListing from '../../components/listings/questListingLine.astro'
import EventListing from '../../components/listings/eventListingLine.astro'
import DatabaseSection from '../../layouts/databaseSection.astro'
import SmallTitle from '../../components/smallTitle.astro'

const description = 'A mostly up-to-date list of NA TA runs'
const fulldata = await getCollection('taInfoData')
const groups = await getCollection('groups')
const changes = await getCollection('changes')
let combined = fulldata

for (const group of groups) {
  combined = combined.filter((data) => !data.id.startsWith(group.id))
}
combined = combined.concat(groups as any).concat(changes as any)

combined.sort(
  (a, b) =>
    b.data.info.releaseDate.valueOf() - a.data.info.releaseDate.valueOf() ||
    b.data.info.releaseNumber - a.data.info.releaseNumber
)
---

<Layout
  title="TA Database - FGO TA"
  currentpage="database"
  descriptionOverride={description}
>
  <SmallTitle
    maintext="TA DATA&shy;BASE"
    subtext="A mostly up-to-date list of NA TA runs"
    fadeout={true}
  />
  <DatabaseSection title="NA Runs" titlehidden={true} displayLine={true}>
    {
      combined.map((quest) => {
        if (['quest', 'group'].includes(quest.data.info.type)) {
          return (
            <QuestListing
              {...{ ...quest.data.info, slug: quest.id }}
              baseurl="database"
            />
          )
        } else {
          return (
            <EventListing
              {...{ ...quest.data.info, slug: quest.id }}
              link={(quest.data as any).link}
              hlcolor={(quest.data as any).color}
            />
          )
        }
      })
    }
  </DatabaseSection>
</Layout>

<style></style>
