<?php
defined('BASEPATH') OR exit('No direct script access allowed');
/** PORTFOLIO LIST — Expects: $projects, $categories. */
?>
<div class="page-head">
	<div><h2>Portfolio</h2><p>Manage campaign case studies and project showcases.</p></div>
	<a href="<?= base_url('admin/portfolio/create') ?>" class="btn btn-primary"><?= bloom_icon('plus', 16) ?> Add Project</a>
</div>

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

<div class="card">
	<div class="card-body flush">
		<?php if ($projects): ?>
			<div class="table-wrap">
				<table class="data" id="projTable">
					<thead><tr><th>Cover</th><th>Project</th><th>Category</th><th>Featured</th><th>Status</th><th class="text-right">Actions</th></tr></thead>
					<tbody>
					<?php foreach ($projects 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>
								<div class="row-sub"><?= html_escape($p['brand']) ?> · <?= html_escape($p['year']) ?></div>
							</td>
							<td><span class="pill pill-grey"><?= html_escape($categories[$p['category']] ?? $p['category']) ?></span></td>
							<td>
								<a href="<?= base_url('admin/portfolio/feature/'.$p['id']) ?>">
									<?= $p['is_featured'] ? '<span class="pill pill-amber">★ Featured</span>' : '<span class="pill pill-grey">—</span>' ?>
								</a>
							</td>
							<td><a href="<?= base_url('admin/portfolio/toggle/'.$p['id']) ?>"><?= status_pill($p['is_active'] ? 'published' : 'draft') ?></a></td>
							<td>
								<div class="row-actions" style="justify-content:flex-end;">
									<a href="<?= base_url('admin/portfolio/edit/'.$p['id']) ?>" class="icon-btn"><?= bloom_icon('edit', 16) ?></a>
									<a href="<?= base_url('admin/portfolio/delete/'.$p['id']) ?>" class="icon-btn danger" data-confirm="Delete this project?"><?= bloom_icon('trash', 16) ?></a>
								</div>
							</td>
						</tr>
					<?php endforeach; ?>
					</tbody>
				</table>
			</div>
		<?php else: ?>
			<div class="empty"><?= bloom_icon('grid', 44) ?><p>No projects yet. Add your first campaign case study.</p></div>
		<?php endif; ?>
	</div>
</div>
