<?php
defined('BASEPATH') OR exit('No direct script access allowed');
/** BLOG LIST — Expects: $posts. */
?>
<div class="page-head">
	<div><h2>Journal</h2><p>Manage articles and editorial content.</p></div>
	<a href="<?= base_url('admin/blog/create') ?>" class="btn btn-primary"><?= bloom_icon('plus', 16) ?> New Article</a>
</div>

<div class="filter-row">
	<div class="search"><?= bloom_icon('search', 17) ?><input type="text" placeholder="Search articles…" data-table-search="#blogTable"></div>
</div>

<div class="card"><div class="card-body flush">
	<?php if ($posts): ?>
		<div class="table-wrap">
			<table class="data" id="blogTable">
				<thead><tr><th>Cover</th><th>Title</th><th>Category</th><th>Status</th><th>Publish Date</th><th class="text-right">Actions</th></tr></thead>
				<tbody>
				<?php foreach ($posts as $p): ?>
					<tr>
						<td><img class="thumb" src="<?= upload_url($p['cover_image']) ?>" alt=""></td>
						<td><div class="row-title"><?= html_escape($p['title']) ?></div></td>
						<td><span class="pill pill-grey"><?= html_escape($p['category'] ?: '—') ?></span></td>
						<td><?= status_pill($p['status']) ?></td>
						<td class="muted"><?= $p['publish_at'] ? nice_date($p['publish_at'], 'd M Y') : '—' ?></td>
						<td><div class="row-actions" style="justify-content:flex-end;">
							<a href="<?= base_url('admin/blog/edit/'.$p['id']) ?>" class="icon-btn"><?= bloom_icon('edit', 16) ?></a>
							<a href="<?= base_url('admin/blog/delete/'.$p['id']) ?>" class="icon-btn danger" data-confirm="Delete this article?"><?= bloom_icon('trash', 16) ?></a>
						</div></td>
					</tr>
				<?php endforeach; ?>
				</tbody>
			</table>
		</div>
	<?php else: ?>
		<div class="empty"><?= bloom_icon('edit', 44) ?><p>No articles yet. Write your first journal entry.</p></div>
	<?php endif; ?>
</div></div>
