---
import { Root } from '../../components/Root'
import Zine from '../../layouts/zine.astro'
import { apiClient } from '../../utils/apiClient'
import { PRERENDERED_ARTICLES_COUNT } from '../../components/Views/Topic'

const slug = Astro.params.slug?.toString() || ''
const articles = await apiClient.getArticlesForTopics({ topicSlugs: [slug], limit: PRERENDERED_ARTICLES_COUNT })
const topic = articles[0].topics.find(({ slug: topicSlug }) => topicSlug === slug)

import { initRouter } from '../../stores/router'

const { pathname, search } = Astro.url
initRouter(pathname, search)

Astro.response.headers.set('Cache-Control', 's-maxage=1, stale-while-revalidate')
---

<Zine>
  <Root topicArticles={articles} topic={topic} client:load />
</Zine>
