<?php
require_once __DIR__ . '/../app/bootstrap.php';
use App\Core\Auth; use App\Core\Database;
Auth::requireLogin('public/login.php');
$products=Database::safeFetchAll('SELECT p.*,v.shop_name FROM wishlists w JOIN products p ON p.id=w.product_id LEFT JOIN vendors v ON v.id=p.vendor_id WHERE w.user_id=? AND p.status="published" ORDER BY w.id DESC',[Auth::id()]);
$pageTitle='Wishlist | '.BRAND_NAME; require ROOT_PATH.'/app/Layouts/frontend_header.php';
?>
<section class="container py-5"><div class="d-flex justify-content-between mb-4"><div><h1>Wishlist</h1><p class="text-muted">Your saved products.</p></div><a class="btn btn-outline-primary" href="<?= url('public/products.php') ?>">Continue Shopping</a></div><div class="row g-4"><?php if(!$products): ?><div class="col-12"><div class="alert alert-info">Your wishlist is empty.</div></div><?php endif; ?><?php foreach($products as $p): ?><div class="col-sm-6 col-lg-3"><div class="product-card"><img class="w-100" src="<?= e(product_image($p)) ?>" alt=""><div class="p-3"><h6><?= e($p['name']) ?></h6><div class="price"><?= money($p['sale_price']?:$p['regular_price']) ?></div><div class="d-grid gap-2 mt-3"><button class="btn btn-primary btn-sm" onclick="phAddCart(<?= (int)$p['id'] ?>,1)">Add to cart</button><button class="btn btn-outline-danger btn-sm" onclick="phToggleList('wishlist',<?= (int)$p['id'] ?>,this,true)">Remove</button></div></div></div></div><?php endforeach; ?></div></section><?php require ROOT_PATH.'/app/Layouts/frontend_footer.php'; ?>
