<?php
defined('BASEPATH') OR exit('No direct script access allowed');
/** EVENTS LIST — Expects: $events, $event_types. */
?>
<div class="page-head">
	<div><h2>Events</h2><p>Manage events, activations and ticketing.</p></div>
	<a href="<?= base_url('admin/events/create') ?>" class="btn btn-primary"><?= bloom_icon('plus', 16) ?> Add Event</a>
</div>

<div class="card"><div class="card-body flush">
	<?php if ($events): ?>
		<div class="table-wrap">
			<table class="data">
				<thead><tr><th>Event</th><th>Date</th><th>Type</th><th>Ticketing</th><th>Status</th><th class="text-right">Actions</th></tr></thead>
				<tbody>
				<?php foreach ($events as $e): $past = strtotime($e['event_date']) < time(); ?>
					<tr>
						<td>
							<div class="row-title"><?= html_escape($e['title']) ?></div>
							<div class="row-sub"><?= bloom_icon('pin', 12) ?> <?= html_escape($e['location']) ?></div>
						</td>
						<td>
							<?= nice_date($e['event_date'], 'd M Y') ?>
							<?php if ($past): ?><br><span class="pill pill-grey">Past</span><?php endif; ?>
						</td>
						<td><span class="pill pill-grey"><?= html_escape($event_types[$e['event_type']] ?? $e['event_type']) ?></span></td>
						<td>
							<?php if ($e['is_paid']): ?>
								<span class="pill pill-amber"><?= money($e['ticket_price']) ?></span>
							<?php elseif ($e['allow_rsvp']): ?>
								<span class="pill pill-blue">RSVP</span>
							<?php else: ?>
								<span class="pill pill-grey">Open</span>
							<?php endif; ?>
						</td>
						<td><a href="<?= base_url('admin/events/toggle/'.$e['id']) ?>"><?= status_pill($e['is_active'] ? 'published' : 'draft') ?></a></td>
						<td><div class="row-actions" style="justify-content:flex-end;">
							<a href="<?= base_url('admin/events/attendees/'.$e['id']) ?>" class="icon-btn" title="Attendees"><?= bloom_icon('users', 16) ?></a>
							<a href="<?= base_url('admin/events/edit/'.$e['id']) ?>" class="icon-btn"><?= bloom_icon('edit', 16) ?></a>
							<a href="<?= base_url('admin/events/delete/'.$e['id']) ?>" class="icon-btn danger" data-confirm="Delete this event?"><?= bloom_icon('trash', 16) ?></a>
						</div></td>
					</tr>
				<?php endforeach; ?>
				</tbody>
			</table>
		</div>
	<?php else: ?>
		<div class="empty"><?= bloom_icon('calendar', 44) ?><p>No events yet. Create your first event.</p></div>
	<?php endif; ?>
</div></div>
