<?php
defined('BASEPATH') OR exit('No direct script access allowed');
/** HERO SLIDES LIST — Expects: $slides. */
?>
<div class="page-head">
	<div><h2>Hero Slides</h2><p>Manage the homepage carousel — images, videos and YouTube embeds.</p></div>
	<a href="<?= base_url('admin/hero/create') ?>" class="btn btn-primary"><?= bloom_icon('plus', 16) ?> Add Slide</a>
</div>

<div class="card">
	<div class="card-body flush">
		<?php if ($slides): ?>
			<div class="table-wrap">
				<table class="data">
					<thead><tr><th>Preview</th><th>Heading</th><th>Type</th><th>Order</th><th>Status</th><th class="text-right">Actions</th></tr></thead>
					<tbody>
					<?php foreach ($slides as $s): ?>
						<tr>
							<td>
								<?php if ($s['media_type'] === 'youtube' && $s['youtube_id']): ?>
									<img class="thumb" src="<?= youtube_thumb($s['youtube_id']) ?>" alt="">
								<?php elseif ($s['image']): ?>
									<img class="thumb" src="<?= upload_url($s['image']) ?>" alt="">
								<?php else: ?>
									<div class="thumb" style="display:grid;place-items:center;"><?= bloom_icon($s['media_type'] === 'video' ? 'film' : 'image', 18) ?></div>
								<?php endif; ?>
							</td>
							<td>
								<div class="row-title"><?= html_escape($s['heading']) ?></div>
								<?php if ($s['eyebrow']): ?><div class="row-sub"><?= html_escape($s['eyebrow']) ?></div><?php endif; ?>
							</td>
							<td><span class="pill pill-grey"><?= html_escape(ucfirst($s['media_type'])) ?></span></td>
							<td><?= (int) $s['sort_order'] ?></td>
							<td>
								<a href="<?= base_url('admin/hero/toggle/'.$s['id']) ?>">
									<?= status_pill($s['is_active'] ? 'published' : 'draft') ?>
								</a>
							</td>
							<td>
								<div class="row-actions" style="justify-content:flex-end;">
									<a href="<?= base_url('admin/hero/edit/'.$s['id']) ?>" class="icon-btn" title="Edit"><?= bloom_icon('edit', 16) ?></a>
									<a href="<?= base_url('admin/hero/delete/'.$s['id']) ?>" class="icon-btn danger" title="Delete"
									   data-confirm="Delete this hero slide?"><?= bloom_icon('trash', 16) ?></a>
								</div>
							</td>
						</tr>
					<?php endforeach; ?>
					</tbody>
				</table>
			</div>
		<?php else: ?>
			<div class="empty"><?= bloom_icon('image', 44) ?><p>No hero slides yet. Add your first slide to build the homepage carousel.</p></div>
		<?php endif; ?>
	</div>
</div>
