<?php
// router.php — dev-server router for `php -S`.
// Emulates the one .htaccess rewrite (/event/{slug} → event/index.php?slug={slug})
// and otherwise lets the built-in server serve real files as-is.

$uri  = urldecode(parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH));
$file = __DIR__ . $uri;

// Serve existing static/PHP files directly
if ($uri !== '/' && file_exists($file) && !is_dir($file)) {
    return false;
}

// Pretty event URL: /event/{slug}
if (preg_match('#^/event/([a-z0-9_\-]+)/?$#i', $uri, $m)) {
    $_GET['slug'] = $m[1];
    require __DIR__ . '/event/index.php';
    return true;
}

// Default: fall through to real files / index.php
if ($uri === '/' ) {
    require __DIR__ . '/index.php';
    return true;
}
return false;
