---
import WebsiteLayout from '@layouts/website/WebsiteLayout.astro';
import { db } from '@db/database.ts';
import Draft from './_draft.astro';
import Submitted from './_submitted.astro';
import Popup from '@components/popup/Popup.svelte';
import ConfirmPopup from '@components/popup/ConfirmPopup.svelte';

const { urlHash } = Astro.params;

const report = urlHash ? await db.getReportByUrlHash({ urlHash: urlHash }) : null;

if (!report) {
  return new Response(null, { status: 404 });
}
---

<WebsiteLayout title="Report">
  {report.createdAt === null ? <Draft report={report} /> : <Submitted report={report} />}
</WebsiteLayout>

<Popup client:idle />
<ConfirmPopup client:idle />
