<?php
defined('BASEPATH') OR exit('No direct script access allowed');
/** TICKETS LIST — Expects: $tickets, $summary. */
?>
<div class="page-head">
	<div><h2>Event Tickets</h2><p>All Paystack ticket purchases across events.</p></div>
	<a href="<?= base_url('admin/tickets/verify') ?>" class="btn btn-ghost"><?= bloom_icon('check', 16) ?> Verify a Ticket</a>
</div>

<div class="stat-cards">
	<div class="stat-card">
		<div class="ico blue"><?= bloom_icon('ticket', 24) ?></div>
		<div><div class="figure"><?= (int) $summary['total'] ?></div><div class="label">Total Orders</div></div>
	</div>
	<div class="stat-card">
		<div class="ico green"><?= bloom_icon('check', 24) ?></div>
		<div><div class="figure"><?= (int) $summary['paid'] ?></div><div class="label">Paid Orders</div></div>
	</div>
	<div class="stat-card">
		<div class="ico amber"><?= bloom_icon('users', 24) ?></div>
		<div><div class="figure"><?= (int) $summary['tickets_sold'] ?></div><div class="label">Tickets Sold</div></div>
	</div>
	<div class="stat-card">
		<div class="ico plum"><?= bloom_icon('tag', 24) ?></div>
		<div><div class="figure"><?= money($summary['revenue']) ?></div><div class="label">Total Revenue</div></div>
	</div>
</div>

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

<div class="card"><div class="card-body flush">
	<?php if ($tickets): ?>
		<div class="table-wrap">
			<table class="data" id="ticketTable">
				<thead><tr><th>Buyer</th><th>Event</th><th>Qty</th><th>Amount</th><th>Code</th><th>Status</th><th>Date</th></tr></thead>
				<tbody>
				<?php foreach ($tickets as $t): ?>
					<tr>
						<td><div class="row-title"><?= html_escape($t['name']) ?></div><div class="row-sub"><?= html_escape($t['email']) ?></div></td>
						<td><?= html_escape($t['event_title']) ?></td>
						<td><?= (int) $t['quantity'] ?></td>
						<td><?= money($t['amount']) ?></td>
						<td><code><?= html_escape($t['ticket_code'] ?: '—') ?></code></td>
						<td><?= status_pill($t['payment_status'] === 'paid' ? 'published' : ($t['payment_status'] === 'failed' ? 'rejected' : 'pending')) ?></td>
						<td class="muted"><?= nice_date($t['created_at']) ?></td>
					</tr>
				<?php endforeach; ?>
				</tbody>
			</table>
		</div>
	<?php else: ?>
		<div class="empty"><?= bloom_icon('ticket', 44) ?><p>No ticket purchases yet.</p></div>
	<?php endif; ?>
</div></div>
