<?php
require_once __DIR__ . '/../includes/config.php';

$lang = (isset($_GET['lang']) && $_GET['lang'] === 'en') ? 'en' : 'fr';
$desc = $lang === 'en'
    ? 'Be my guest at my 50th birthday banquet. Dress code: dinner outfit.'
    : 'Soyez mon invite au banquet de mon 50e anniversaire. Tenue de soiree.';

$lines = [
    'BEGIN:VCALENDAR',
    'VERSION:2.0',
    'PRODID:-//PKO 50//RSVP//EN',
    'CALSCALE:GREGORIAN',
    'METHOD:PUBLISH',
    'BEGIN:VEVENT',
    'UID:pko50-' . EVENT_START . '@pko50',
    'DTSTAMP:' . gmdate('Ymd\THis\Z'),
    'DTSTART;TZID=Africa/Lome:' . EVENT_START,
    'DTEND;TZID=Africa/Lome:' . EVENT_END,
    'SUMMARY:' . EVENT_TITLE,
    'LOCATION:' . EVENT_VENUE,
    'DESCRIPTION:' . $desc,
    'BEGIN:VALARM',
    'TRIGGER:-P1D',
    'ACTION:DISPLAY',
    'DESCRIPTION:' . EVENT_TITLE,
    'END:VALARM',
    'END:VEVENT',
    'END:VCALENDAR',
];

header('Content-Type: text/calendar; charset=utf-8');
header('Content-Disposition: attachment; filename="pko-at-50.ics"');
echo implode("\r\n", $lines) . "\r\n";
