<?php
/// file: app/View/admin/journal/index.php

declare(strict_types=1);

/** @var list<array<string, mixed>> $posts */
?>
<div class="flex items-center justify-between">
    <h1 class="text-2xl font-semibold text-white">Journal</h1>
    <a href="<?= e(url('/admin/journal/create')) ?>" class="rounded-full bg-white px-4 py-2 text-xs font-semibold text-carbon">New</a>
</div>
<div class="mt-8 overflow-x-auto">
    <table class="min-w-full text-left text-sm text-silver-300">
        <thead class="border-b border-white/10 text-xs uppercase text-silver-500">
            <tr><th class="py-3 pr-4">Title</th><th class="py-3 pr-4">Slug</th><th class="py-3">Actions</th></tr>
        </thead>
        <tbody>
        <?php foreach ($posts as $p): ?>
            <tr class="border-b border-white/5">
                <td class="py-3 pr-4 text-white"><?= e((string) $p['title']) ?></td>
                <td class="py-3 pr-4"><?= e((string) $p['slug']) ?></td>
                <td class="py-3">
                    <a class="text-electric-300" href="<?= e(url('/admin/journal/edit/' . (int) $p['id'])) ?>">Edit</a>
                    <form method="post" action="<?= e(url('/admin/journal/delete/' . (int) $p['id'])) ?>" class="inline" onsubmit="return confirm('Delete?');"><?= \App\Core\Csrf::field() ?><button type="submit" class="ml-3 text-red-400">Delete</button></form>
                </td>
            </tr>
        <?php endforeach; ?>
        </tbody>
    </table>
</div>
