<?php
$page_title       = 'MenUp365 Events | Weekly Calls, Gatherings & Pillar Conversations';
$page_description = 'Join MenUp365 events — weekly Tuesday accountability calls at 7:30 PM EST, pillar conversations, and annual brotherhood gatherings. See what\'s coming up and register.';
$page_canonical   = 'https://menup365.com/events';
$page_active_nav  = 'events';

// Load events from data file (SSOT)
$events_data = [];
$events_file = __DIR__ . '/data/events.json';
if (file_exists($events_file)) {
    $events_data = json_decode(file_get_contents($events_file), true) ?: [];
}

// Calculate next Tuesday 7:30 EST for the recurring weekly call
$tz = new DateTimeZone('America/New_York');
$next_tuesday = new DateTime('next tuesday 19:00', $tz);

$page_schema = [
    '@context' => 'https://schema.org',
    '@graph' => [
        [
            '@type' => 'CollectionPage',
            'name' => 'MenUp365 Events',
            'url'  => 'https://menup365.com/events',
            'description' => $page_description,
        ],
        [
            '@type' => 'Event',
            '@id'   => 'https://menup365.com/events#weekly-call',
            'name'  => 'MenUp365 Weekly Accountability Call',
            'description' => 'Show up, check in, and stay on track with brothers who hold each other accountable. Every Tuesday 7:30 PM EST. Open to all members.',
            'startDate' => $next_tuesday->format('c'),
            'endDate'   => (clone $next_tuesday)->modify('+90 minutes')->format('c'),
            'eventSchedule' => [
                '@type' => 'Schedule',
                'repeatFrequency' => 'P1W',
                'byDay' => 'https://schema.org/Tuesday',
                'startTime' => '19:00',
                'scheduleTimezone' => 'America/New_York',
            ],
            'eventAttendanceMode' => 'https://schema.org/OnlineEventAttendanceMode',
            'eventStatus' => 'https://schema.org/EventScheduled',
            'location' => [
                '@type' => 'VirtualLocation',
                'url'   => 'https://menup365.com/events/register?event=weekly-accountability-call',
            ],
            'organizer' => [
                '@type' => 'Organization',
                'name'  => 'MenUp365',
                'url'   => 'https://menup365.com',
            ],
            'offers' => [
                '@type' => 'Offer',
                'url'   => 'https://menup365.com/membership',
                'price' => '19.99',
                'priceCurrency' => 'USD',
                'availability'  => 'https://schema.org/InStock',
                'validFrom' => date('c'),
            ],
            'image' => 'https://menup365.com/assets/images/events/accountability-call.jpg',
        ],
    ],
];
include 'includes/header.php';
?>

<div class="page-header">
  <div class="container">
    <span class="section-label">Events</span>
    <h1 class="page-header__title">Events &amp; <span class="text-gold">Gatherings</span></h1>
    <p class="page-header__subtitle">Every Tuesday, brothers show up for each other. Here is what is coming up &mdash; and how to get plugged in.</p>
  </div>
</div>

<section class="section dark-section">
  <div class="container">
    <!-- Recurring Events -->
    <div class="mb-8">
      <h2 class="section-title reveal" style="font-size:var(--text-2xl);">
        <span class="text-gold">&#9679;</span> Recurring Events
      </h2>
      <div class="grid" style="gap:var(--space-5);">
        <?php foreach ($events_data as $evt):
          if (($evt['type'] ?? '') !== 'recurring') continue;
          $event = $evt;
          $event['cta_text'] = 'Register';
          $event['cta_url']  = '/events/register?event=' . urlencode($evt['slug'] ?? '');
          include 'includes/event-card.php';
        endforeach; ?>
      </div>
    </div>

    <!-- Upcoming Events -->
    <div>
      <h2 class="section-title reveal" style="font-size:var(--text-2xl);">
        <span class="text-gold">&#9679;</span> Upcoming Events
      </h2>
      <div class="grid" style="gap:var(--space-5);">
        <?php
        $has_upcoming = false;
        foreach ($events_data as $evt):
          if (($evt['type'] ?? '') !== 'one-time') continue;
          $has_upcoming = true;
          $event = $evt;
          $event['cta_text'] = 'Register';
          $event['cta_url']  = '/events/register?event=' . urlencode($evt['slug'] ?? '');
          include 'includes/event-card.php';
        endforeach;

        if (!$has_upcoming): ?>
          <div class="card reveal" style="text-align:center;padding:var(--space-10);">
            <p style="font-size:var(--text-lg);color:var(--text-muted-dark);">More events coming soon. Stay connected to be the first to know.</p>
            <a href="/#stay-connected" class="btn-primary" style="margin-top:var(--space-5);">Stay Connected</a>
          </div>
        <?php endif; ?>
      </div>
    </div>
  </div>
</section>

<section class="section gold-section">
  <div class="container">
    <div class="cta-band reveal">
      <h2 class="cta-band__title">Never Miss an Event</h2>
      <p class="cta-band__text">Members get early access, exclusive invites, and weekly reminders for every call and gathering.</p>
      <a href="/membership" class="btn-dark btn-lg">Become a Member</a>
    </div>
  </div>
</section>

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