<?php
$activityRegistry = [
    'fun-day' => ['title' => 'Fun Day', 'max' => 6, 'tone' => 'secondary', 'icon' => 'party-popper'],
    'rickshaw-ride' => ['title' => 'Rickshaw Ride', 'max' => 4, 'tone' => 'primary', 'icon' => 'bike'],
    'food-stalls' => ['title' => 'Food & Market Stalls', 'max' => 2, 'tone' => 'accent', 'icon' => 'utensils-crossed'],
    'longhi-race' => ['title' => 'Longhi Race', 'max' => 8, 'tone' => 'primary', 'icon' => 'ship'],
    'family-picnic' => ['title' => 'Family Picnic', 'max' => 10, 'tone' => 'accent', 'icon' => 'trees'],
    'sack-race' => ['title' => 'Sack Race', 'max' => 4, 'tone' => 'primary', 'icon' => 'award'],
];

$slug = isset($_GET['activity']) ? preg_replace('/[^a-z0-9-]/', '', strtolower((string) $_GET['activity'])) : '';
$activity = $activityRegistry[$slug] ?? null;

include 'includes/header.php';
?>

<?php if (!$activity): ?>
<section class="py-5 form-page-section" style="min-height: 60vh;">
    <div class="container py-5 text-center">
        <h1 class="form-page-card-title mb-3">Activity Not Found</h1>
        <p class="text-muted mb-4">We could not find that activity. Please pick one from the activities list.</p>
        <a href="activities.php" class="btn btn-primary rounded-pill px-4">Back to Activities</a>
    </div>
</section>
<?php else:
    $tone = $activity['tone'];
    $iconBoxClass = 'form-page-activity-icon form-page-activity-icon--' . $tone;
?>
<section class="form-page-hero form-page-hero--primary form-page-hero--pad-activity">
    <div class="container text-center position-relative" style="z-index: 2;">
        <div class="<?php echo htmlspecialchars($iconBoxClass, ENT_QUOTES, 'UTF-8'); ?> mx-auto mb-4">
            <i data-lucide="<?php echo htmlspecialchars($activity['icon'], ENT_QUOTES, 'UTF-8'); ?>" class="lucide-activity"></i>
        </div>
        <h1 class="form-page-hero-title text-white mb-3">Register for <?php echo htmlspecialchars($activity['title'], ENT_QUOTES, 'UTF-8'); ?></h1>
    </div>
</section>

<section class="py-5 form-page-section">
    <div class="container py-0">
        <div class="form-page-frame form-page-frame--narrow mx-auto">
            <a href="activities.php" class="form-page-back d-inline-flex align-items-center gap-2 text-decoration-none text-muted small mb-4">
                <i data-lucide="arrow-left" class="lucide-16"></i>
                Back to Activities
            </a>
            <div class="form-page-card card border-0 shadow-lg rounded-4">
                <div class="card-body p-4 p-md-5">
                    <h2 class="form-page-card-title mb-4">Your Details</h2>
                    <form action="handlers/global-handler.php" method="POST" data-ajax-handler="global" autocomplete="on">
                        <input type="hidden" name="registration_type" value="activity">
                        <input type="hidden" name="activity_slug" value="<?php echo htmlspecialchars($slug, ENT_QUOTES, 'UTF-8'); ?>">

                        <div class="row g-4">
                            <div class="col-12">
                                <label class="form-label form-page-label" for="full_name">Full Name *</label>
                                <input type="text" class="form-control form-page-control" id="full_name" name="full_name" placeholder="Your full name" required>
                            </div>
                            <div class="col-12">
                                <label class="form-label form-page-label" for="email">Email Address *</label>
                                <input type="email" class="form-control form-page-control" id="email" name="email" placeholder="your@email.com" required>
                            </div>
                            <div class="col-12">
                                <label class="form-label form-page-label" for="phone">Phone Number</label>
                                <input type="tel" class="form-control form-page-control" id="phone" name="phone" placeholder="+44 7700 000000">
                            </div>
                            <div class="col-12">
                                <label class="form-label form-page-label" for="participants">Number of Participants *</label>
                                <input type="number" class="form-control form-page-control" id="participants" name="participants" min="1" max="<?php echo (int) $activity['max']; ?>" value="1" required>
                                <p class="form-page-hint text-muted small mt-1 mb-0">Max <?php echo (int) $activity['max']; ?> per registration</p>
                            </div>
                            <div class="col-12">
                                <label class="form-label form-page-label" for="notes">Additional Notes</label>
                                <textarea class="form-control form-page-control" id="notes" name="notes" rows="3" placeholder="Any special requirements or questions..."></textarea>
                            </div>
                            <div class="col-12 pt-1">
                                <button type="submit" class="btn w-100 form-page-btn-secondary py-2 rounded-pill fw-semibold">Complete Registration</button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</section>
<?php endif; ?>

<?php include 'includes/footer.php'; ?>
