<?php
require_once __DIR__ . '/../app/bootstrap.php';
use App\Core\Database;
$shops=Database::safeFetchAll('SELECT v.*,u.name owner_name,COUNT(p.id) product_count FROM vendors v LEFT JOIN users u ON u.id=v.user_id LEFT JOIN products p ON p.vendor_id=v.id AND p.status="published" WHERE v.status="approved" GROUP BY v.id ORDER BY v.rating DESC,v.id DESC');
$pageTitle='Vendor Shops | '.BRAND_NAME; require ROOT_PATH.'/app/Layouts/frontend_header.php';
?>
<section class="container py-5"><div class="landing-hero p-4 p-lg-5 mb-4"><h1>Vendor Shops</h1><p class="lead mb-0">Approved stores selling through the marketplace.</p></div><div class="row g-4">
<?php if(!$shops): ?><div class="col-12"><div class="alert alert-info">No approved shops found.</div></div><?php endif; ?>
<?php foreach($shops as $s): ?><div class="col-md-6 col-lg-4"><div class="card module-card h-100"><div class="card-body"><div class="d-flex align-items-center gap-3 mb-3"><?php if(!empty($s['logo'])): ?><img src="<?= e(product_image(['image'=>$s['logo']])) ?>" class="rounded" width="70" height="70" style="object-fit:cover" alt=""><?php endif; ?><div><h4 class="mb-1"><?= e($s['shop_name']) ?></h4><small class="text-muted"><?= e($s['owner_name'] ?? '') ?></small></div></div><p class="text-muted"><?= e($s['address'] ?? '') ?></p><div class="d-flex justify-content-between"><span>★ <?= number_format((float)$s['rating'],1) ?> · <?= (int)$s['product_count'] ?> products</span><a class="btn btn-primary btn-sm" href="<?= url('shop/'.$s['slug']) ?>">Visit Shop</a></div></div></div></div><?php endforeach; ?>
</div></section><?php require ROOT_PATH.'/app/Layouts/frontend_footer.php'; ?>
