<?php
/**
 * 芋头CMS - 家具定制企业网站模板
 * ============================================================================
 * 版权所�?2016-2028 沅陵县乌托邦网络服务有限公司，并保留所有权利�? * 网站地址: http://www.yutoucms.cn
 * ----------------------------------------------------------------------------
 * 如果商业用途务必到官方购买正版授权, 以免引起不必要的法律纠纷�? * ============================================================================
 * Author: 芋头 <mxgsf@qq.com>
 * Date: 2026-6-1
 */
if (!defined('ROOT_PATH')) { exit('Access Denied'); }
$topChannels = $db->fetchAll("SELECT * FROM {$db->table('channel')} WHERE parent_id = 0 AND is_show = 1 ORDER BY list_order ASC, id ASC");
$sitePhone = isset($siteConfig['site_phone']) ? $siteConfig['site_phone'] : '';
$siteAddress = isset($siteConfig['site_address']) ? $siteConfig['site_address'] : '';
?>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title><?php echo isset($pageTitle) ? $pageTitle . ' - ' : ''; ?><?php echo htmlspecialchars(isset($siteConfig['site_name']) ? $siteConfig['site_name'] : '家具定制'); ?></title>
<meta name="keywords" content="<?php echo htmlspecialchars(isset($siteConfig['site_keywords']) ? $siteConfig['site_keywords'] : ''); ?>">
<meta name="description" content="<?php echo htmlspecialchars(isset($siteConfig['site_description']) ? $siteConfig['site_description'] : ''); ?>">
<link rel="stylesheet" href="<?php echo $site['template_dir']; ?>css/main.css">
<?php echo isset($extraHead) ? $extraHead : ''; ?>
</head>
<body>

<!-- 顶部导航 -->
<div class="nav-top">
<div class="container">
<div>
<?php if ($sitePhone): ?>
<span>📞 <?php echo htmlspecialchars($sitePhone); ?></span>
<?php endif; ?>
<?php if ($siteAddress): ?>
<span>📍 <?php echo htmlspecialchars($siteAddress); ?></span>
<?php endif; ?>
</div>
<div>
<a href="/public/index.php?m=guestbook">留言</a>
<span>&nbsp;|&nbsp;</span>
<a href="<?php echo getUrl('home'); ?>">收藏本站</a>
</div>
</div>
</div>

<!-- 主导�?-->
<header class="header" id="header">
<div class="nav-main">
<div class="container">
<a href="<?php echo getUrl('home'); ?>" class="logo">
<div class="logo-text">
<?php echo htmlspecialchars(isset($siteConfig['site_name']) ? $siteConfig['site_name'] : '家具定制'); ?>
<small>FURNITURE</small>
</div>
</a>

<button class="nav-toggle" id="navToggle" onclick="toggleMobileNav()">
<span></span><span></span><span></span>
</button>

<ul class="nav-menu" id="navMenu">
<?php
// 首页链接
$homeActive = (isset($module) ? $module : '') === 'index' ? ' class="active"' : '';
?>
<li class="nav-item<?php echo (isset($module) ? $module : '') === 'index' ? ' active' : ''; ?>">
<a href="<?php echo getUrl('home'); ?>">网站首页</a>
</li>

<?php foreach ($topChannels as $ch): ?>
<?php
$subChannels = $db->fetchAll("SELECT * FROM {$db->table('channel')} WHERE parent_id = ? AND is_show = 1 ORDER BY list_order ASC, id ASC", [$ch['id']]);
$hasSub = !empty($subChannels);
$chUrl = getUrl('channel', $ch['id']);
?>
<li class="nav-item<?php echo (isset($module) ? $module : '') === 'channel' && (isset($id) ? $id : 0) == $ch['id'] ? ' active' : ''; ?>">
<a href="<?php echo $chUrl; ?>"><?php echo htmlspecialchars($ch['channel_name']); ?></a>
<?php if ($hasSub): ?>
<ul class="nav-sub">
<?php foreach ($subChannels as $sub): ?>
<li><a href="<?php echo getUrl('channel', $sub['id']); ?>"><?php echo htmlspecialchars($sub['channel_name']); ?></a></li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
</li>
<?php endforeach; ?>

</ul>
</div>
</div>
</header>

<script>
function toggleMobileNav() {
    document.getElementById('navMenu').classList.toggle('open');
}
window.addEventListener('scroll', function() {
    var h = document.getElementById('header');
    if (window.scrollY > 10) h.classList.add('scrolled');
    else h.classList.remove('scrolled');
});
</script>
