<?php
require_once 'includes/bootstrap.php'; require_once 'includes/product-card.php'; include 'includes/header.php';
$id=isset($_GET['id'])?(int)$_GET['id']:0;
$c=mysqli_query($conn,"SELECT * FROM categories WHERE id=$id LIMIT 1"); $cat=$c?mysqli_fetch_assoc($c):null;
$ids=array($id); $subs=mysqli_query($conn,"SELECT id FROM categories WHERE parent_id=$id AND status=1"); if($subs){ while($s=mysqli_fetch_assoc($subs)) $ids[]=(int)$s['id']; }
$in=implode(',',array_map('intval',$ids));
$rs=mysqli_query($conn,"SELECT p.*,b.name brand_name FROM products p LEFT JOIN brands b ON p.brand_id=b.id WHERE p.status=1 AND p.category_id IN ($in) ORDER BY p.id DESC LIMIT 60");
$title=$cat?category_name($cat,$lang):'Category';
$banner=$cat?clean_upload_path($cat['banner_image'], clean_upload_path($cat['image'], category_product_image($conn,$id))):'assets/images/products/no-image.svg';
?>
<main class="container section category-page">
  <div class="category-banner"><img src="<?php echo e(thumb_url($banner,1320,260,'cover')); ?>" loading="lazy" decoding="async" alt="<?php echo e($title); ?>"><div class="category-banner-caption"><h2><?php echo e($title); ?></h2></div></div>
  <div class="title-row"><h2><?php echo e($title); ?></h2><a class="see-all" href="search.php?lang=<?php echo e($lang); ?>"><?php echo e(t('see_all')); ?></a></div>
  <div class="product-row"><?php if($rs): while($p=mysqli_fetch_assoc($rs)): render_product_card($conn,$p,$lang); endwhile; endif; ?></div>
</main>
<?php include 'includes/footer.php'; ?>
