<?php
define('SITE_LOADED', true);
require_once __DIR__ . '/config.php';

$currentCat = isset($_GET['cat']) ? (string)$_GET['cat'] : '';
if ($currentCat !== '' && !isset($categories[$currentCat])) $currentCat = '';
$kw = isset($_GET['kw']) ? trim((string)$_GET['kw']) : '';
if (mb_strlen($kw) > 30) $kw = mb_substr($kw, 0, 30);

$list = $products;
if ($currentCat !== '') $list = products_by_cat($currentCat);
if ($kw !== '') {
    $list = array_values(array_filter($list, function($p) use ($kw) {
        return mb_strpos($p['name'], $kw) !== false || mb_strpos($p['summary'], $kw) !== false;
    }));
}

$pageTitle = $currentCat ? $categories[$currentCat] . '_规划设计服务' : '业务范围';
$pageKeywords = '北京规划设计公司,国土空间规划,控制性详细规划,城市设计,乡村振兴规划,产业园区规划,建筑设计,景观设计';
$pageDescription = '北京旭日规划设计有限公司业务范围：国土空间总体规划、控制性详细规划、修建性详细规划、城市设计、乡村振兴与村庄规划、产业园区规划、文旅旅游规划、建筑设计与景观设计，提供全流程规划设计技术服务。';
include __DIR__ . '/includes/header.php';
?>

<section class="page-banner">
    <div class="container">
        <h1>业务范围</h1>
        <p>首页 / 业务范围<?php echo $currentCat ? ' / ' . e($categories[$currentCat]) : ''; ?></p>
    </div>
</section>

<section class="section">
    <div class="container">
        <div class="filter-bar">
            <div class="filter-tabs">
                <a href="services.php" class="<?php echo $currentCat === '' ? 'active' : ''; ?>">全部业务</a>
                <?php foreach ($categories as $ck => $cn): ?>
                <a href="services.php?cat=<?php echo e($ck); ?>" class="<?php echo $currentCat === $ck ? 'active' : ''; ?>"><?php echo e($cn); ?></a>
                <?php endforeach; ?>
            </div>
            <form action="services.php" method="get" class="filter-search">
                <?php if ($currentCat): ?><input type="hidden" name="cat" value="<?php echo e($currentCat); ?>"><?php endif; ?>
                <input type="text" name="kw" placeholder="搜索业务..." value="<?php echo e($kw); ?>">
                <button type="submit" class="btn btn-primary">搜索</button>
            </form>
        </div>

        <?php if (empty($list)): ?>
        <div class="empty"><p>暂无相关业务，请尝试其他分类或关键词。</p><a href="services.php" class="btn btn-primary">查看全部业务</a></div>
        <?php else: ?>
        <div class="product-grid">
            <?php foreach ($list as $p): ?>
            <div class="product-card">
                <div class="product-icon"><?php echo $p['icon']; ?></div>
                <span class="product-cat"><?php echo e($categories[$p['cat']]); ?></span>
                <h3><a href="service.php?id=<?php echo e($p['id']); ?>"><?php echo e($p['name']); ?></a></h3>
                <p><?php echo e($p['summary']); ?></p>
                <a href="service.php?id=<?php echo e($p['id']); ?>" class="btn btn-outline btn-block">查看详情</a>
            </div>
            <?php endforeach; ?>
        </div>
        <?php endif; ?>
    </div>
</section>

<?php include __DIR__ . '/includes/footer.php'; ?>
