<!DOCTYPE html>
<html lang="cz">
<head>
    <title>Epinger 2</title>
    <?php 
    include "utilities/head.php"; 
    
    // Get the requested URL path
    $requestPath = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);

    $index_css = ['css/index/index.css', 'css/index/about_us.css', 'css/index/carousel.css', 'css/index/contact.css', 'css/index/products.css', 'css/index/instagram.css','css/articles/other/reference.css' , 'css/tools/email-me.css', 'css/index/reference.css'];
    
    $routes = [
        '' => ['template' => 'articles/other/default.php', 'css' => [$index_css]], // Example of multiple CSS files
        '/' => ['template' => 'articles/other/default.php', 'css' => [$index_css]], // Example of multiple CSS files
        '/index.php' => ['template' => 'articles/other/default.php', 'css' => [$index_css]], // Example of multiple CSS files
    
        '/contacts' => ['template' => 'contacts.php','css' => ['/css/articles/contacts.css', '/css/articles/article-base.css']],
        '/about-us' => ['template' => 'articles/other/about-us.php', 'css' => ['/css/articles/other/about-us.css', '/css/articles/article-base.css']],
        '/reference' => ['template' => 'articles/other/reference.php', 'css' => ['/css/articles/other/reference.css', '/css/articles/article-base.css']],
        '/brany' => ['template' => 'articles/brany.php', 'css' => ['/css/articles/brany.css', '/css/articles/article-base.css']],
        '/vrata' => ['template' => 'articles/vrata.php', 'css' => ['/css/articles/vrata.css', '/css/articles/article-base.css']],
        '/akce' => ['template' => 'articles/akcevertisment.php', 'css' => ['/css/articles/akce.css', '/css/articles/article-base.css']],
        '/komplex' => ['template' => 'articles/komplex.php', 'css' => ['/css/articles/komplex.css', '/css/articles/article-base.css']],
        '/zavory' => ['template' => 'articles/zavory.php', 'css' => ['/css/articles/zavory.css', '/css/articles/article-base.css']],
        '/rolety' => ['template' => 'articles/rolety.php', 'css' => ['/css/articles/rolety.css', '/css/articles/article-base.css']],
        '/servis' => ['template' => 'articles/service.php', 'css' => ['/css/articles/service.css', '/css/articles/article-base.css']],
        '/zaluzie' => ['template' => 'articles/zaluzie.php', 'css' => ['/css/articles/zaluzie.css', '/css/articles/article-base.css']],
        '/reklamy' => ['template' => 'articles/reklamy.php', 'css' => ['/css/articles/reklamy.css', '/css/articles/article-base.css']],
    ];
    
    // Check if the requested path matches a defined route
    if (isset($routes[$requestPath]) && isset($routes[$requestPath]['css'])) {
        // Output the CSS files
        foreach ($routes[$requestPath]['css'] as $cssFile) {
            if (is_array($cssFile)) {
                // If $cssFile is an array, handle it appropriately
                foreach ($cssFile as $singleCssFile) {
                    echo '<link rel="stylesheet" type="text/css" href="' . $singleCssFile . '">';
                }
            } else {
                // If $cssFile is a single CSS file, include it directly
                echo '<link rel="stylesheet" type="text/css" href="' . $cssFile . '">';
            }
        }
    }

    
    
    ?>
</head>
<body>
    <?php include "tools/nav.php"; ?>
    <main>
        <?php
            // Check if the requested path matches a defined route
            if (isset($routes[$requestPath])) {
                // Include the template if available
                if (isset($routes[$requestPath]['template'])) {
                    $templatePath = $routes[$requestPath]['template'];
                    if (file_exists($templatePath) && filesize($templatePath) > 0) {
                        include $templatePath;
                    }
                }
            } else {
                // If no matching route is found, include the 404 page
                include "utilities/404.php";
            }
        ?>
    </main>
    <?php include "tools/contact.php";?>
    <?php include "tools/map.php"; ?>
</body>
</html>
