---
import DefaultLayout from "../../layouts/DefaultLayout.astro";
import Markdown from "../../islands/Markdown.jsx";
import { marked } from "marked";
import { getDocumentBySlug } from "../../lib/documents";

const { slug } = Astro.params;

const doc = slug ? getDocumentBySlug(slug) : null;
if (!doc || doc.visible !== true) {
  return Astro.redirect("/dokumenty", 302);
}

const html = marked.parse(doc.content);
---

<DefaultLayout title={doc.title}>
  <section class="f-section">
    <div class="f-section-grid-single">
      <a href="/dokumenty" class="text-sm opacity-70 hover:opacity-100">
        ← Wróć do dokumentów
      </a>

      <h1 class="f-section-title">
        {doc.title}
      </h1>

      <div class="fuz-markdown max-w-none">
        <Markdown text={html} />
      </div>
    </div>
  </section>
</DefaultLayout>
