<?php
/**
 * Mobile Bottom Navigation Menu
 */
// Get current page name to highlight the active menu icon
$current_page = basename($_SERVER['PHP_SELF']);

// Fetch help link from database safely
try { 
    $pdo->exec("ALTER TABLE site_settings ADD COLUMN help_link VARCHAR(255) DEFAULT '#' "); 
} catch (PDOException $e) {
    // Column likely already exists
}

$stmt_site_nav = $pdo->query("SELECT help_link FROM site_settings LIMIT 1");
$nav_settings = $stmt_site_nav->fetch(PDO::FETCH_ASSOC);
$help_link = !empty($nav_settings['help_link']) ? $nav_settings['help_link'] : '#';
?>

<style>
    @import url('https://fonts.googleapis.com/css2?family=Outfit:wght@400;600&display=swap');

    .mobile-bottom-menu {
        font-family: 'Outfit', sans-serif;
        display: flex;
        justify-content: space-around;
        align-items: center;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        background: #ffffff;
        border-top: 1px solid #e2e8f0;
        padding: 10px 0;
        z-index: 1000;
        border-radius: 0 !important; /* Forces corner radius to be completely flat */
    }
    
    .menu-item {
        display: flex;
        flex-direction: column;
        align-items: center;
        text-decoration: none;
        color: #000000;
        font-size: 0.75rem;
        font-weight: 600;
        transition: color 0.3s ease;
        position: relative;
    }
    
    .menu-item img {
        width: 28px;
        height: 28px;
        margin-bottom: 4px;
        transition: all 0.3s ease;
    }
    
    .menu-item.active {
        color: #00059E;
    }

    .menu-item.home-btn {
        background-color: #00059E;
        border-radius: 50%;
        width: 60px;
        height: 60px;
        justify-content: center;
        margin-top: -30px;
        border: 4px solid #ffffff;
        color: white;
    }

    .menu-item.home-btn img {
        filter: brightness(0) invert(1);
        width: 32px;
        height: 32px;
        margin-bottom: 0;
    }

    .menu-item.home-btn span {
        display: none;
    }

</style>

<nav class="mobile-bottom-menu">

    <?php $is_shop = ($current_page == 'products.php' && !isset($_GET['search']) || $current_page == 'categories.php'); ?>
    <a href="products" class="menu-item <?php echo $is_shop ? 'active' : ''; ?>">
        <img src="https://img.icons8.com/?size=100&id=15893&format=png&color=<?php echo $is_shop ? '00059E' : '000000'; ?>" alt="Shop">
        <span>Shop</span>
    </a>

    <?php $is_search = isset($_GET['search']); ?>
    <a href="products?search=" class="menu-item <?php echo $is_search ? 'active' : ''; ?>">
        <img src="https://img.icons8.com/?size=100&id=14079&format=png&color=<?php echo $is_search ? '00059E' : '000000'; ?>" alt="Search">
        <span>Search</span>
    </a>

    <?php $is_home = ($current_page == 'index.php' || $current_page == 'index' || $current_page == ''); ?>
    <a href="/" class="menu-item home-btn <?php echo $is_home ? 'active' : ''; ?>">
        <img src="https://img.icons8.com/?size=100&id=6g6b5Mh-1uJ7&format=png&color=000000" alt="Home">
        <span>Home</span>
    </a>

    <a href="<?php echo htmlspecialchars($help_link); ?>" class="menu-item" target="_blank">
        <img src="https://img.icons8.com/?size=100&id=Cq0bCO6BqKJw&format=png&color=000000" alt="Help">
        <span>Help</span>
    </a>

    <?php $is_account = ($current_page == 'account.php' || $current_page == 'login.php' || $current_page == 'register.php'); ?>
    <a href="account" class="menu-item <?php echo $is_account ? 'active' : ''; ?>">
        <img src="https://img.icons8.com/?size=100&id=15263&format=png&color=<?php echo $is_account ? '00059E' : '000000'; ?>" alt="Account">
        <span>Profile</span>
    </a>
    
</nav>
