<?php 
require dirname(__FILE__, 2).'/vendor/autoload.php';

//route
$requestUri = $_GET['p'] ?? parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
$page = match (true) {
  ('/' === $requestUri) => 'page.php',
  ('/admin/' === $requestUri) => 'admin/index.php',
  ('/admin/pages/' === $requestUri) => 'admin/pages.php',
  ('/admin/slots/' === $requestUri) => 'admin/slots.php',
  ('/admin/authors/' === $requestUri) => 'admin/authors.php',
  ('/editor/uploads/' === $requestUri) => 'upload.php',
  ('/verstka/' === $requestUri) => 'verstka.php',
  (preg_match('#^/redirect/([\w-]+)/$#', $requestUri, $matches) === 1) => 'redirect.php',
  (preg_match('#^/([\w-]+)/$#', $requestUri, $matches) === 1) => 'page.php',
  default => '404.php',
};

//slug
if (isset($matches[1])) {
  $slug = $matches[1];
}

//connect
$content = (!empty($page) && file_exists(Config::PATH['src']."/Pages/{$page}"))
  ? require Config::PATH['src']."/Pages/{$page}"
  : 'Select a page to view please'
?>

<?=$content ?>