<?php require_once 'includes/bootstrap.php'; require_once 'includes/product-card.php'; include 'includes/header.php'; $id=isset($_GET['id'])?(int)$_GET['id']:0; $q=mysqli_query($conn,"SELECT p.*,b.name brand_name,c.name_en cat_en,c.name_ar cat_ar,c.name_ku cat_ku FROM products p LEFT JOIN brands b ON p.brand_id=b.id LEFT JOIN categories c ON p.category_id=c.id WHERE p.id=$id LIMIT 1"); if(!$q || !mysqli_num_rows($q)){ echo '<main class="container section"><h2>Product not found</h2></main>'; include 'includes/footer.php'; exit;} $p=mysqli_fetch_assoc($q); $imgs=product_images($conn,$id); $related=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=".(int)$p['category_id']." AND p.id<>$id ORDER BY p.id DESC LIMIT 4"); ?>
<main class="container section"><div class="wide-body" style="grid-template-columns:520px 1fr;gap:40px"><div><?php foreach($imgs as $im): ?><div class="cat-img" style="width:100%;height:420px;border-radius:18px"><img src="<?php echo e(thumb_url($im,900,700,'contain')); ?>" loading="lazy" decoding="async" style="width:95%;height:95%;object-fit:contain" alt=""></div><?php break; endforeach; ?></div><div><div class="badge"><?php echo e($p['brand_name']); ?></div><h1><?php echo e(product_name($p,$lang)); ?></h1><div class="wide-price"><strong><?php echo money_iqd(product_final_price($p)); ?></strong><?php if((float)$p['old_price']>0): ?><span><?php echo money_iqd($p['old_price']); ?></span><?php endif; ?></div><p><?php echo nl2br(e(product_desc($p,$lang))); ?></p><button class="primary-btn add-to-cart-btn" data-id="<?php echo $id; ?>"><?php echo e(t('add_to_cart')); ?></button></div></div><section class="section"><div class="title-row"><h2>Related Products</h2></div><div class="product-row"><?php if($related): while($rp=mysqli_fetch_assoc($related)): render_product_card($conn,$rp,$lang); endwhile; endif; ?></div></section></main><?php include 'includes/footer.php'; ?>
