<?php
declare(strict_types=1);
require_once __DIR__ . '/../app/bootstrap.php';
use App\Core\Database;
$slug=trim((string)($_GET['slug']??''));
$vendor=Database::safeFetchOne('SELECT * FROM vendors WHERE slug=? AND status="approved" LIMIT 1',[$slug]);
if(!$vendor){http_response_code(404);$pageTitle='Shop Not Found';include ROOT_PATH.'/app/Layouts/frontend_header.php';echo '<section class="container py-5"><div class="alert alert-warning">Shop not found or not approved.</div></section>';include ROOT_PATH.'/app/Layouts/frontend_footer.php';exit;}
$products=Database::safeFetchAll('SELECT p.* FROM products p WHERE p.vendor_id=? AND p.status="published" ORDER BY p.id DESC',[$vendor['id']]);
$pageTitle=$vendor['shop_name'].' | Shop';include ROOT_PATH.'/app/Layouts/frontend_header.php';
?>
<section class="container py-5"><div class="landing-hero p-5 mb-4" <?php if(!empty($vendor['banner'])): ?>style="background-image:linear-gradient(90deg,rgba(255,255,255,.95),rgba(255,255,255,.72)),url('<?= e(product_image(['image'=>$vendor['banner']])) ?>');background-size:cover;background-position:center"<?php endif; ?>><div class="d-flex align-items-center gap-3"><?php if(!empty($vendor['logo'])): ?><img src="<?= e(product_image(['image'=>$vendor['logo']])) ?>" width="100" height="100" class="rounded border" style="object-fit:contain" alt=""><?php endif; ?><div><h1><?= e($vendor['shop_name']) ?></h1><p><?= e($vendor['address']??'') ?></p><p class="mb-0"><?= nl2br(e($vendor['policies']??'')) ?></p></div></div></div><div class="row g-4"><?php if(!$products): ?><div class="col-12"><div class="alert alert-info">This shop has no published products.</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'; ?>
