<?php
defined('BASEPATH') OR exit('No direct script access allowed');
/** TICKET VERIFY — Expects: $code, $ticket, $event. */
?>
<div class="page-head">
	<div><h2>Verify Ticket</h2><p>Check a ticket code at the event gate.</p></div>
	<a href="<?= base_url('admin/tickets') ?>" class="btn btn-ghost">← All Tickets</a>
</div>

<div class="card" style="max-width:520px;">
	<div class="card-head"><h3>Enter Ticket Code</h3></div>
	<div class="card-body">
		<form method="get" action="<?= base_url('admin/tickets/verify') ?>">
			<div style="display:flex;gap:8px;">
				<input type="text" name="code" value="<?= html_escape($code) ?>" placeholder="e.g. BLM-A1B2C3"
				       style="flex:1;padding:11px 13px;border-radius:9px;border:1.5px solid var(--line);text-transform:uppercase;">
				<button type="submit" class="btn btn-primary"><?= bloom_icon('search', 16) ?> Check</button>
			</div>
		</form>
	</div>
</div>

<?php if ($code !== NULL && $code !== ''): ?>
	<?php if ($ticket && $ticket['payment_status'] === 'paid'): ?>
		<div class="card" style="max-width:520px;border-left:5px solid var(--green);">
			<div class="card-body">
				<div class="alert alert-success" style="margin-bottom:14px;">✓ Valid ticket — admit <?= (int) $ticket['quantity'] ?> guest<?= $ticket['quantity'] == 1 ? '' : 's' ?></div>
				<div class="form-grid cols-2">
					<div><label class="muted" style="font-size:.78rem;">Holder</label><div><?= html_escape($ticket['name']) ?></div></div>
					<div><label class="muted" style="font-size:.78rem;">Quantity</label><div><?= (int) $ticket['quantity'] ?></div></div>
					<div><label class="muted" style="font-size:.78rem;">Event</label><div><?= html_escape($event ? $event['title'] : '—') ?></div></div>
					<div><label class="muted" style="font-size:.78rem;">Amount Paid</label><div><?= money($ticket['amount']) ?></div></div>
				</div>
			</div>
		</div>
	<?php elseif ($ticket): ?>
		<div class="card" style="max-width:520px;border-left:5px solid var(--amber);">
			<div class="card-body">
				<div class="alert alert-error">⚠ Ticket found but payment status is "<?= html_escape($ticket['payment_status']) ?>" — not valid for entry.</div>
			</div>
		</div>
	<?php else: ?>
		<div class="card" style="max-width:520px;border-left:5px solid var(--red);">
			<div class="card-body">
				<div class="alert alert-error">✗ No ticket found with that code.</div>
			</div>
		</div>
	<?php endif; ?>
<?php endif; ?>
