---
import { Root } from '../components/Root'
import Prerendered from '../main.astro'
import { apiClient } from '../utils/apiClient'
import { initRouter } from '../stores/router'

const params: URLSearchParams = Astro.url.searchParams
const q = params.get('q')
const searchResults = await apiClient.getShouts({ filters: { title: q, body: q }, limit: 50 })

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

<Prerendered>
  <Root searchResults={searchResults} client:load />
</Prerendered>
