<?php
declare(strict_types=1);
require_once __DIR__ . '/../app/bootstrap.php';
use App\Core\Database;
$slug=trim((string)($_GET['slug']??''));
$brand=Database::safeFetchOne('SELECT * FROM brands WHERE slug=? AND status="active" LIMIT 1',[$slug]);
if(!$brand){http_response_code(404);$pageTitle='Brand Not Found';include ROOT_PATH.'/app/Layouts/frontend_header.php';echo '<section class="container py-5"><div class="alert alert-warning">Brand not found.</div></section>';include ROOT_PATH.'/app/Layouts/frontend_footer.php';exit;}
$products=Database::safeFetchAll('SELECT p.*,v.shop_name FROM products p LEFT JOIN vendors v ON v.id=p.vendor_id WHERE p.brand_id=? AND p.status="published" ORDER BY p.id DESC',[$brand['id']]);
$pageTitle=($brand['meta_title']?:$brand['name']).' | Brand';$pageDescription=$brand['meta_description']?:$brand['description'];include ROOT_PATH.'/app/Layouts/frontend_header.php';
?>
<section class="container py-5"><div class="d-flex align-items-center gap-3 mb-4"><?php if(!empty($brand['logo'])): ?><img src="<?= e(product_image(['image'=>$brand['logo']])) ?>" width="90" height="90" style="object-fit:contain" class="border rounded" alt=""><?php endif; ?><div><h1 class="section-title mb-1"><?= e($brand['name']) ?></h1><p class="text-muted mb-0"><?= e($brand['description']??'') ?></p></div></div><div class="row g-4"><?php if(!$products): ?><div class="col-12"><div class="alert alert-info">No published products for this brand.</div></div><?php endif; ?><?php foreach($products as $p): ?><div class="col-sm-6 col-lg-3"><div class="product-card h-100"><img class="w-100" src="<?= e(product_image($p)) ?>" alt="<?= e($p['name']) ?>"><div class="p-3"><h6><?= e($p['name']) ?></h6><div class="price"><?= money($p['sale_price']?:$p['regular_price']) ?></div><a class="btn btn-sm btn-primary mt-2" href="<?= url('product/'.$p['slug']) ?>">View</a></div></div></div><?php endforeach; ?></div></section>
<?php include ROOT_PATH.'/app/Layouts/frontend_footer.php'; ?>
