---
import SubsiteBase from "../../../layouts/SubsiteBase.astro";
import SubsiteRoot from "../../../components/SubsiteAppLayout.jsx";
import { generateCsrfToken } from "../../../utils/csrf.js";
import { getCookieId, generateNonce, createNonceCookie } from "../../../utils/rateLimit.js";

// Generate CSRF token during SSR
let cookieId = getCookieId(Astro.request);
const hadCookie = !!cookieId;

if (!cookieId) {
    cookieId = generateNonce();
}

const csrfToken = generateCsrfToken(cookieId);

// Set cookie if new session
if (!hadCookie) {
    Astro.response.headers.set('Set-Cookie', createNonceCookie(cookieId));
}
---

<SubsiteBase title="Request Media">
    <script is:inline define:vars={{ csrfToken }}>
        (function(w,d){w[d]=atob(btoa(csrfToken))})(window,'_t');
    </script>
    <section class="page-section">
        <SubsiteRoot child="ReqForm" client:only="react" />
    </section>
</SubsiteBase>
