---
import Seo from '@components/Seo.astro';
import { buildUrl } from '@utils/url-builder';
import { Page } from './_index.data';

export const prerender = Page.prerender;
export const getStaticPaths = Page.getStaticPaths;

const props = await Page.getData(Astro);

const pageTitle = `${props.collection} | ${props.data.name}`.replace(/^\w/, (c) => c.toUpperCase());

const { pathname } = Astro.url;
const redirectUrl = buildUrl(pathname + '/' + props.data.latestVersion, false, true);
---

<!doctype html>
<html lang="en">
  <head>
    <Seo title={`EventCatalog | ${pageTitle}`} ogTitle={pageTitle} />
  </head>
  <body>
    <p>You are being redirected to <a href={redirectUrl}>{redirectUrl}</a></p>
  </body>
</html>

<script define:vars={{ redirectUrl }}>
  document.addEventListener('DOMContentLoaded', () => {
    const searchParams = window.location.search;
    const fullRedirectUrl = redirectUrl + searchParams;
    window.location.href = fullRedirectUrl;
  });
</script>
