<?php

$request = trim(parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH), '/');
$segments = $request === '' ? [] : explode('/', $request);

$segments = array_map('urldecode', $segments);

$type = $segments[1] ?? null;
$slug = $segments[2] ?? null;

$allowed_types = ["display", "audioplayer"];

if (($type !== null && !in_array($type, $allowed_types)) || count($segments) > 3) {
    http_response_code(400);
    include $baseDir . "/error-pages/400.html";
    exit;
}

define('APP_ROUTER', true);

if ($type === "display") {
    require __DIR__ . "/display.php";
} elseif ($type === "audioplayer") {
    require __DIR__ . "/audio.php";
}
