---
import Admin from '../../../layouts/Admin.astro';
import PostForm from '../../../components/admin/PostForm.astro';
import { getDb } from '../../../lib/db';
import { getPostById, canModifyPost } from '../../../lib/posts';
export const prerender = false;
const post = getPostById(getDb(), Number(Astro.params.id));
if (!post) return Astro.redirect('/admin');
const u = Astro.locals.user!;
if (!canModifyPost(u.role, u.id, post)) return Astro.redirect('/admin');
---
<Admin title={`Modifica: ${post.title}`}>
  <h1>Modifica articolo</h1>
  <script id="initial-body" type="text/plain" set:html={post.body_html}></script>
  <PostForm post={post} />
</Admin>
