<?php
defined('BASEPATH') OR exit('No direct script access allowed');
/** EVENT DETAIL — Expects: $event, $gallery, $is_past, $rsvp_count, $event_types. */
$e = $event;
?>
<section class="page-hero">
	<div class="container">
		<div class="page-hero-inner" data-reveal style="max-width:780px;">
			<div class="breadcrumb">
				<a href="<?= base_url() ?>">Home</a> / <a href="<?= base_url('events') ?>">Events</a> / <span><?= html_escape($e['title']) ?></span>
			</div>
			<span class="eyebrow"><?= html_escape($event_types[$e['event_type']] ?? $e['event_type']) ?></span>
			<h1><?= html_escape($e['title']) ?></h1>
			<p><?= html_escape($e['excerpt']) ?></p>
			<div style="display:flex;gap:24px;margin-top:20px;flex-wrap:wrap;color:rgba(255,255,255,.85);">
				<span><?= bloom_icon('calendar', 17) ?> <?= nice_date($e['event_date'], 'l, d M Y') ?></span>
				<span><?= bloom_icon('pin', 17) ?> <?= html_escape($e['location']) ?></span>
				<?php if ($e['event_time']): ?><span><?= bloom_icon('sparkle', 17) ?> <?= html_escape($e['event_time']) ?></span><?php endif; ?>
			</div>
		</div>
	</div>
</section>

<section class="section section--tight">
	<div class="container">
		<div data-reveal style="border-radius:var(--radius-lg);overflow:hidden;background:var(--ink);">
			<img src="<?= upload_url($e['cover_image'], 'img/event-fallback.jpg') ?>" alt="<?= html_escape($e['title']) ?>" style="width:100%;display:block;">
		</div>
	</div>
</section>

<section class="section section--tight">
	<div class="container">
		<div class="card-grid cols-2" style="gap:48px;align-items:start;">
			<!-- DESCRIPTION -->
			<div data-reveal>
				<span class="eyebrow">About the Event</span>
				<h2 style="margin:14px 0;">What to expect</h2>
				<div style="color:var(--ink-soft);font-size:1.05rem;"><?= nl2br(html_escape($e['description'])) ?></div>
			</div>

			<!-- RSVP / TICKET PANEL -->
			<div data-reveal data-delay="2">
				<div class="form-card">
					<?= flash() ?>
					<?php if ($is_past): ?>
						<h3 style="margin-bottom:8px;">This event has ended</h3>
						<p style="color:var(--ink-soft);">Thank you to everyone who joined us. Explore the recap gallery below.</p>

					<?php elseif ($e['is_paid']): ?>
						<span class="eyebrow">Get Your Ticket</span>
						<h3 style="margin:12px 0 6px;"><?= money($e['ticket_price']) ?> <span style="font-size:.9rem;color:var(--ink-soft);">per ticket</span></h3>
						<p style="color:var(--ink-soft);margin-bottom:18px;">Secure your place at this ticketed event. Payment is processed securely via Paystack.</p>
						<form action="<?= base_url('pay/ticket/'.$e['id']) ?>" method="post">
							<?= form_hidden($this->security->get_csrf_token_name(), $this->security->get_csrf_hash()) ?>
							<div class="field"><label>Full Name <span class="req">*</span></label><input type="text" name="name" required></div>
							<div class="field"><label>Email <span class="req">*</span></label><input type="email" name="email" required></div>
							<div class="field-row">
								<div class="field"><label>Phone</label><input type="text" name="phone"></div>
								<div class="field"><label>Tickets</label>
									<select name="quantity">
										<?php for ($q = 1; $q <= 6; $q++): ?><option value="<?= $q ?>"><?= $q ?></option><?php endfor; ?>
									</select>
								</div>
							</div>
							<button type="submit" class="btn btn-primary btn-block btn-lg">
								<?= bloom_icon('ticket', 18) ?> Proceed to Payment
							</button>
						</form>

					<?php elseif ($e['allow_rsvp']): ?>
						<span class="eyebrow">Reserve Your Spot</span>
						<h3 style="margin:12px 0 6px;">RSVP — Free Entry</h3>
						<p style="color:var(--ink-soft);margin-bottom:18px;">
							<?= $rsvp_count ?> <?= $rsvp_count === 1 ? 'person has' : 'people have' ?> RSVP'd so far.
						</p>
						<form action="<?= base_url('events/rsvp/'.$e['id']) ?>" method="post">
							<?= form_hidden($this->security->get_csrf_token_name(), $this->security->get_csrf_hash()) ?>
							<div class="field"><label>Full Name <span class="req">*</span></label><input type="text" name="name" required></div>
							<div class="field"><label>Email <span class="req">*</span></label><input type="email" name="email" required></div>
							<div class="field-row">
								<div class="field"><label>Phone</label><input type="text" name="phone"></div>
								<div class="field"><label>Guests</label>
									<select name="guests">
										<?php for ($g = 1; $g <= 5; $g++): ?><option value="<?= $g ?>"><?= $g ?></option><?php endfor; ?>
									</select>
								</div>
							</div>
							<button type="submit" class="btn btn-primary btn-block btn-lg"><?= bloom_icon('check', 18) ?> Confirm RSVP</button>
						</form>

					<?php else: ?>
						<h3 style="margin-bottom:8px;">Join us</h3>
						<p style="color:var(--ink-soft);">No registration needed — simply turn up and enjoy.</p>
						<a href="<?= whatsapp_link('the '.$e['title'].' event') ?>" class="btn btn-primary btn-block" target="_blank" style="margin-top:14px;">
							<?= bloom_icon('whatsapp', 18) ?> Ask a Question
						</a>
					<?php endif; ?>
				</div>
			</div>
		</div>
	</div>
</section>

<!-- RECAP GALLERY -->
<?php if ($gallery): ?>
<section class="section section--cream section--tight">
	<div class="container">
		<div class="section-head" data-reveal><span class="eyebrow">Recap</span><h2 style="margin-top:14px;">Event gallery</h2></div>
		<div class="card-grid cols-4">
			<?php foreach ($gallery as $i => $img): ?>
				<a href="<?= upload_url($img) ?>" data-lightbox="<?= upload_url($img) ?>" class="work-media" data-reveal data-delay="<?= ($i % 4) + 1 ?>" style="border-radius:var(--radius);aspect-ratio:1;cursor:zoom-in;">
					<img src="<?= upload_url($img) ?>" alt="Event photo" loading="lazy">
				</a>
			<?php endforeach; ?>
		</div>
	</div>
</section>
<?php endif; ?>
