<?php
require_once 'includes/config.php';
require_once 'includes/db.php';
require_once 'includes/functions.php';

// Dobijanje trenutnog URL-a
$current_page = basename($_SERVER['PHP_SELF']);

// Dobijanje kategorija za meni
$categories = get_rows("SELECT id, name, slug FROM categories WHERE parent_id IS NULL ORDER BY name ASC");

// Broj stavki u korpi
$cart_count = 0;
$cart = get_cart();
foreach ($cart as $quantity) {
    $cart_count += $quantity;
}
?>
<!DOCTYPE html>
<html lang="sr">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <?php
    // Ako su meta podaci dinamički, postaviti ih ovde
    echo generate_meta_tags();
    ?>
    
    <!-- Favicon -->
    <link rel="icon" href="/favicon.ico">
    <link rel="apple-touch-icon" href="/apple-touch-icon.png">
    
    <!-- Preload fontova -->
    <link rel="preload" href="/assets/fonts/HugongIcons.woff2" as="font" type="font/woff2" crossorigin>
    
    <!-- CSS -->
    <link rel="stylesheet" href="/assets/css/styles.css">
    <link rel="stylesheet" href="/assets/css/home.css">
    <link rel="stylesheet" href="/assets/css/mobile-product.css">
    <link rel="stylesheet" href="/assets/css/product-modern.css">


    
    <!-- Strukturirani podaci za organizaciju -->
    <script type="application/ld+json">
    {
      "@context": "https://schema.org",
      "@type": "Organization",
      "name": "<?php echo get_setting('site_name', 'Hugong Aparati'); ?>",
      "url": "<?php echo SITE_URL; ?>",
      "logo": "<?php echo SITE_URL; ?>/uploads/hugong-logo.png",
      "contactPoint": {
        "@type": "ContactPoint",
        "telephone": "<?php echo get_setting('contact_phone', '+381 65 8065 065'); ?>",
        "contactType": "customer service",
        "availableLanguage": "Serbian"
      },
      "sameAs": [
        "https://www.facebook.com/hugongaparati",
        "https://www.instagram.com/hugongaparati"
      ]
    }
    </script>
</head>
<body>
    <!-- Desktop Header -->
    <header class="site-header desktop-only">
        <div class="container">
            <div class="header-main">
                <!-- Logo -->
                <a href="/" class="logo">
                    <?php if (file_exists($_SERVER['DOCUMENT_ROOT'] . '/uploads/hugong-logo.png')): ?>
                        <img src="/uploads/hugong-logo.png" alt="<?php echo get_setting('site_name', 'Hugong Aparati'); ?>" width="180" height="60">
                    <?php else: ?>
                        <h1><?php echo get_setting('site_name', 'HUGONG APARATI'); ?></h1>
                    <?php endif; ?>
                </a>

                <!-- Contact button and cart -->
                <div class="header-actions">
                    <!-- Phone button -->
                    <a href="tel:+381658065065" class="contact-button">
                        <svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
                            <path d="M22 16.92v3a2 2 0 0 1-2.18 2 19.79 19.79 0 0 1-8.63-3.07 19.5 19.5 0 0 1-6-6 19.79 19.79 0 0 1-3.07-8.67A2 2 0 0 1 4.11 2h3a2 2 0 0 1 2 1.72 12.84 12.84 0 0 0 .7 2.81 2 2 0 0 1-.45 2.11L8.09 9.91a16 16 0 0 0 6 6l1.27-1.27a2 2 0 0 1 2.11-.45 12.84 12.84 0 0 0 2.81.7A2 2 0 0 1 22 16.92z"></path>
                        </svg>
                        +381 65 8065 065
                    </a>
                    
                    <!-- Shopping Cart -->
                    <a href="/cart.php" class="cart-icon">
                        <svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
                            <circle cx="9" cy="21" r="1"></circle>
                            <circle cx="20" cy="21" r="1"></circle>
                            <path d="M1 1h4l2.68 13.39a2 2 0 0 0 2 1.61h9.72a2 2 0 0 0 2-1.61L23 6H6"></path>
                        </svg>
                        <span class="cart-count"><?php echo $cart_count; ?></span>
                    </a>
                </div>
            </div>
        </div>
        
        <!-- Main Navigation -->
        <nav class="main-navigation">
            <div class="container">
                <ul class="nav-menu">
                    <li class="<?php echo $current_page === 'index.php' ? 'active' : ''; ?>">
                        <a href="/">POČETNA</a>
                    </li>
                    <li class="<?php echo $current_page === 'svi-proizvodi.php' ? 'active' : ''; ?>">
                        <a href="/svi-proizvodi">SVI APARATI</a>
                    </li>
                    <?php foreach ($categories as $category): ?>
                    <li class="<?php echo isset($_GET['category']) && $_GET['category'] === $category['slug'] ? 'active' : ''; ?>">
                        <a href="/<?php echo $category['slug']; ?>"><?php echo strtoupper($category['name']); ?></a>
                    </li>
                    <?php endforeach; ?>
                    <li class="<?php echo $current_page === 'o-nama.php' ? 'active' : ''; ?>">
                        <a href="/o-nama.php">O NAMA</a>
                    </li>
                    <li class="<?php echo $current_page === 'kontakt.php' ? 'active' : ''; ?>">
                        <a href="/kontakt.php">KONTAKT</a>
                    </li>
                </ul>
            </div>
        </nav>
    </header>

<!-- Mobile Header -->
<header class="mobile-header mobile-only">
    <!-- Yellow top bar -->
    <div class="mobile-top-bar">
        <a href="/" class="mobile-logo">
            <img src="/uploads/hugong-logo.png" alt="<?php echo get_setting('site_name', 'Hugong Aparati'); ?>" width="120">
        </a>
        
        <div class="top-actions">
            <a href="/cart.php" class="mobile-cart">
                <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
                    <circle cx="9" cy="21" r="1"></circle>
                    <circle cx="20" cy="21" r="1"></circle>
                    <path d="M1 1h4l2.68 13.39a2 2 0 0 0 2 1.61h9.72a2 2 0 0 0 2-1.61L23 6H6"></path>
                </svg>
                <span class="cart-count"><?php echo $cart_count; ?></span>
            </a>
            
            <button class="menu-btn" id="mobile-menu-toggle" aria-label="Menu">
                <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="#333" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
                    <line x1="3" y1="12" x2="21" y2="12"></line>
                    <line x1="3" y1="6" x2="21" y2="6"></line>
                    <line x1="3" y1="18" x2="21" y2="18"></line>
                </svg>
                <span>MENI</span>
            </button>
        </div>
    </div>
</header>

<!-- Mobile Menu Overlay -->
<div class="mobile-menu-overlay" id="mobile-menu-overlay"></div>

<!-- Mobile Menu Panel -->
<div class="mobile-menu-panel" id="mobile-menu-panel">
    <!-- Address and Contact Section -->
    <div class="mobile-contact-section">
        <div class="contact-item">
            <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="#f6cc00" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
                <path d="M21 10c0 7-9 13-9 13s-9-6-9-13a9 9 0 0 1 18 0z"></path>
                <circle cx="12" cy="10" r="3"></circle>
            </svg>
            <div class="contact-text">
                <strong>Oškara Davića 2,</strong>
                <span>34000 Kragujevac</span>
            </div>
        </div>
        
        <div class="contact-item">
            <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="#f6cc00" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
                <path d="M22 16.92v3a2 2 0 0 1-2.18 2 19.79 19.79 0 0 1-8.63-3.07 19.5 19.5 0 0 1-6-6 19.79 19.79 0 0 1-3.07-8.67A2 2 0 0 1 4.11 2h3a2 2 0 0 1 2 1.72 12.84 12.84 0 0 0 .7 2.81 2 2 0 0 1-.45 2.11L8.09 9.91a16 16 0 0 0 6 6l1.27-1.27a2 2 0 0 1 2.11-.45 12.84 12.84 0 0 0 2.81.7A2 2 0 0 1 22 16.92z"></path>
            </svg>
            <div class="contact-text">
                <span>065/8-065-065</span>
            </div>
        </div>
    </div>
    
    <!-- Login/Register Section -->
    <div class="mobile-auth-section">
        <a href="/login.php" class="auth-link">
            <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
                <path d="M20 21v-2a4 4 0 0 0-4-4H8a4 4 0 0 0-4 4v2"></path>
                <circle cx="12" cy="7" r="4"></circle>
            </svg>
            <span>Registracija/Login</span>
        </a>
    </div>
    
    <!-- Navigation Menu -->
    <nav class="mobile-nav">
        <ul>
            <?php foreach ($categories as $category): ?>
            <li>
                <a href="/<?php echo $category['slug']; ?>"><?php echo $category['name']; ?></a>
            </li>
            <?php endforeach; ?>
            <li><a href="/o-nama.php">O nama</a></li>
            <li><a href="/kontakt.php">Kontakt</a></li>
        </ul>
    </nav>
    
    <!-- Contact Email -->
    <div class="mobile-contact-email">
        <div class="contact-item">
            <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="#f6cc00" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
                <path d="M4 4h16c1.1 0 2 .9 2 2v12c0 1.1-.9 2-2 2H4c-1.1 0-2-.9-2-2V6c0-1.1.9-2 2-2z"></path>
                <polyline points="22,6 12,13 2,6"></polyline>
            </svg>
            <div class="contact-text">
                <span>info@hugong-aparati.rs</span>
                <span>info@agras.rs</span>
            </div>
        </div>
    </div>
</div>
    
    <div class="content-wrapper">