<?php
require_once __DIR__ . '/db.php';
$current_page = basename($_SERVER['PHP_SELF']);
?>
<!DOCTYPE html>
<html lang="id">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title><?php echo isset($page_title) ? $page_title . ' - ' . $settings['company_name'] : $settings['company_name'] . ' | ' . $settings['tagline']; ?></title>
    <meta name="description" content="<?php echo isset($page_desc) ? htmlspecialchars($page_desc) : htmlspecialchars($settings['about_short']); ?>">
    <meta name="robots" content="index, follow">
    <meta name="keywords" content="batu split, abu batu, batu screening, base course, batu alam, terrazzo, pt namora nexa niaga, supplier batu split jakarta, aggregates supplier">
    
    <!-- Open Graph / Facebook -->
    <meta property="og:type" content="website">
    <meta property="og:url" content="<?php echo (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]"; ?>">
    <meta property="og:title" content="<?php echo isset($page_title) ? $page_title . ' - ' . $settings['company_name'] : $settings['company_name'] . ' | ' . $settings['tagline']; ?>">
    <meta property="og:description" content="<?php echo isset($page_desc) ? htmlspecialchars($page_desc) : htmlspecialchars($settings['about_short']); ?>">
    <meta property="og:image" content="<?php echo (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://$_SERVER[HTTP_HOST]" . (strpos($_SERVER['REQUEST_URI'], '/admin/') !== false ? '../' : '') . "assets/images/hero_bg.jpg"; ?>">
    <meta property="og:site_name" content="<?php echo htmlspecialchars($settings['company_name']); ?>">
    
    <!-- Twitter -->
    <meta property="twitter:card" content="summary_large_image">
    <meta property="twitter:title" content="<?php echo isset($page_title) ? $page_title . ' - ' . $settings['company_name'] : $settings['company_name'] . ' | ' . $settings['tagline']; ?>">
    <meta property="twitter:description" content="<?php echo isset($page_desc) ? htmlspecialchars($page_desc) : htmlspecialchars($settings['about_short']); ?>">
    
    <link rel="canonical" href="<?php echo (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]"; ?>">
    
    <!-- Google Fonts -->
    <link href="https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@300;400;500;600;700;800&display=swap" rel="stylesheet">
    
    <!-- FontAwesome for Icons -->
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
    
    <!-- Main Style -->
    <link rel="stylesheet" href="<?php echo (strpos($_SERVER['REQUEST_URI'], '/admin/') !== false) ? '../assets/css/style.css' : 'assets/css/style.css'; ?>">
</head>
<body>

    <!-- Header Navigation -->
    <header>
        <div class="nav-container">
            <?php
            $is_admin = (strpos($_SERVER['REQUEST_URI'], '/admin/') !== false);
            $logo_dir = $is_admin ? '../assets/images/' : 'assets/images/';
            
            $logo_path = $logo_dir . 'logo.png';
            if (!file_exists($logo_path)) {
                $logo_path = ($is_admin ? '../assets/' : 'assets/') . 'logo.png';
            }
            if (!file_exists($logo_path)) {
                $logo_path = $logo_dir . 'logo_namora.png';
            }
            ?>
            <a href="index.php" class="logo">
                <?php if (file_exists($logo_path)): ?>
                    <img src="<?php echo $logo_path; ?>" alt="Logo <?php echo $settings['company_name']; ?>" style="height: 55px; width: auto; object-fit: contain;">
                <?php endif; ?>
                <div class="logo-text">
                    <span class="brand-name"><?php echo $settings['company_name']; ?></span>
                    <span class="brand-tagline"><?php echo $settings['tagline']; ?></span>
                </div>
            </a>
            
            <button class="menu-toggle" id="menuToggle" aria-label="Toggle menu">
                <span></span>
                <span></span>
                <span></span>
            </button>
            
            <nav class="nav-menu" id="navMenu">
                <a href="index.php" class="nav-link <?php echo $current_page == 'index.php' ? 'active' : ''; ?>">Beranda</a>
                <?php if (isset($settings['menu_about_visible']) && $settings['menu_about_visible'] == 1): ?>
                    <a href="about.php" class="nav-link <?php echo $current_page == 'about.php' ? 'active' : ''; ?>">Tentang Kami</a>
                <?php endif; ?>
                <?php if (isset($settings['menu_products_visible']) && $settings['menu_products_visible'] == 1): ?>
                    <a href="products.php" class="nav-link <?php echo $current_page == 'products.php' || $current_page == 'product-detail.php' ? 'active' : ''; ?>">Produk</a>
                <?php endif; ?>
                <?php if (isset($settings['menu_gallery_visible']) && $settings['menu_gallery_visible'] == 1): ?>
                    <a href="gallery.php" class="nav-link <?php echo $current_page == 'gallery.php' ? 'active' : ''; ?>">Galeri</a>
                <?php endif; ?>
                <?php if (isset($settings['menu_blog_visible']) && $settings['menu_blog_visible'] == 1): ?>
                    <a href="blog.php" class="nav-link <?php echo $current_page == 'blog.php' || $current_page == 'blog-detail.php' ? 'active' : ''; ?>">Artikel</a>
                <?php endif; ?>
                <?php if (isset($settings['menu_contact_visible']) && $settings['menu_contact_visible'] == 1): ?>
                    <a href="contact.php" class="nav-link <?php echo $current_page == 'contact.php' ? 'active' : ''; ?>">Kontak</a>
                    <a href="contact.php" class="nav-btn">Hubungi Kami</a>
                <?php endif; ?>
            </nav>
        </div>
    </header>
