<?php
require_once "includes/conn.php";

$base = "/tycon/";

$current = trim(parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH), '/');
$basePath = trim(parse_url($base, PHP_URL_PATH), '/'); // if $base = http://localhost/tycon/
$current = str_replace($basePath, '', $current);
$current = trim($current, '/');

function isActive($path, $current)
{
    return $path === $current ? 'act' : '';
}



$stmt = $conn->prepare("
    SELECT c.*, p.name AS project_name
    FROM categories c
    INNER JOIN projects p 
        ON c.project_id = p.id
    WHERE p.name = :project_name
");

$stmt->execute([
    ':project_name' => 'Products'
]);

$cat = $stmt->fetchAll(PDO::FETCH_ASSOC);
?>
<div class="top-bar-area inc-pad inc-border">
    <div class="container">
        <div class="row align-center text-light">
            <div class="col-lg-6 info">
                <p>
                    <i class="fa fa-location-dot"></i> Surgical House, 312/2B, kandy
                    Road, Kadawatha, Sri Lanka.
                </p>
            </div>
            <div class="col-lg-6 text-end item-flex">
                <div class="info">
                    <ul>
                        <li>
                            <a href="tel:+94722920113">+94722920113</a>
                        </li>
                    </ul>
                </div>
                <div class="social">
                    <ul>
                        <li>
                            <a href="#">
                                <i class="fab fa-facebook-f"></i>
                            </a>
                        </li>
                        <li>
                            <a href="#">
                                <i class="fab fa-whatsapp"></i>
                            </a>
                        </li>
                        <li>
                            <a href="#">
                                <i class="fab fa-youtube"></i>
                            </a>
                        </li>
                        <li>
                            <a href="#">
                                <i class="fa fa-map-marked-alt"></i>
                            </a>
                        </li>
                    </ul>
                </div>
            </div>
        </div>
    </div>
</div>

<!-- Header 
    ============================================= -->
<header>
    <!-- Start Navigation -->
    <nav class="navbar mobile-sidenav navbar-sticky navbar-default validnavs dark">
        <div class="container d-flex justify-content-between align-items-center">
            <!-- Start Header Navigation -->
            <div class="navbar-header">
                <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#navbar-menu">
                    <i class="fa fa-bars"></i>
                </button>
                <a class="navbar-brand" href="index.php">
                    <img src="/tycon/assets/img/logo.png" class="logo" alt="Logo" />
                </a>
            </div>
            <!-- End Header Navigation -->

            <!-- Collect the nav links, forms, and other content for toggling -->
            <div class="collapse navbar-collapse" id="navbar-menu">
                <div class="collapse-header">
                    <img src="/tycon/assets/img/logo.png" alt="Logo" />
                    <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#navbar-menu">
                        <i class="fa fa-times"></i>
                    </button>
                </div>

                <ul class="nav navbar-nav navbar-right" data-in="fadeInDown" data-out="fadeOutUp">
                    <li>
                        <a href="<?= $base ?>" class="<?= ($current == '' ? 'act' : '') ?>">Home</a>
                    </li>

                    <li>
                        <a href="<?= $base ?>about-us" class="<?= isActive('about-us', $current) ?>">About Us</a>
                    </li>

                    <li class="dropdown">
                        <a href="#" class="dropdown-toggle <?= (str_contains($current, 'products') || str_contains($current, 'product')) ? 'act' : '' ?>" data-toggle="dropdown">Products</a>
                        <ul class="dropdown-menu">

                            <?php if (count($cat) > 0): ?>
                                <?php foreach ($cat as $row): ?>

                                    <?php
                                    $isActiveProduct =
                                        ($current == 'products/' . $row['id']) ? 'act' : '';
                                    ?>

                                    <li>
                                        <a href="<?= $base ?>products/<?= $row['id']; ?>" class="<?= $isActiveProduct ?>">
                                            <?= htmlspecialchars($row['name']); ?>
                                        </a>
                                    </li>

                                <?php endforeach; ?>
                            <?php else: ?>
                                <li><a href="#">No Products Found</a></li>
                            <?php endif; ?>

                        </ul>
                    </li>

                    <li>
                        <a href="<?= $base ?>articles/2"
                            class="<?= str_contains($current, 'articles') ? 'act' : '' ?>">
                            Articles
                        </a>
                    </li>

                    <li>
                        <a href="#contact">Contact</a>
                    </li>
                </ul>
            </div>
            <!-- /.navbar-collapse -->

            <!-- Start Atribute Navigation -->
            <div class="attr-right">
                <!-- Start Atribute Navigation -->
                <div class="attr-nav">
                    <ul>
                        <li class="contact">
                            <div class="call">
                                <!-- <div class="icon">
                      <i class="fas fa-stethoscope"></i>
                    </div> -->
                                <div class="info">
                                    <!-- <p>Have any Questions?</p> -->
                                    <h5>
                                        <a href="mailto:info@crysta.com">info@bestup.com</a>
                                    </h5>
                                </div>
                            </div>
                        </li>
                    </ul>
                </div>
                <!-- End Atribute Navigation -->
            </div>
            <!-- End Atribute Navigation -->
        </div>
        <!-- Overlay screen for menu -->
        <div class="overlay-screen"></div>
        <!-- End Overlay screen for menu -->
    </nav>
    <!-- End Navigation -->
</header>
<!-- End Header -->