{% extends "base.html" %} {% from "components/listing_card.html" import listing_card with context %} {% from "components/pagination.html" import render_pagination %} {% from "components/discovery_section.html" import discovery_row, discovery_categories with context %} {% from "components/skeleton.html" import skeleton_row %} {% from "components/empty_state.html" import empty_state %} {% block title %}Marketplace · CampusCart{% endblock %} {% block head_extra %} {% endblock %} {% block content %} {% set has_filters = q or category_id or condition or min_price or max_price %}
{# Welcome banner: real greeting + real live listing count (dismissible). #} {% if current_user.is_authenticated %} {% set welcome_name = current_user.profile.full_name.split(' ')[0] if current_user.profile and current_user.profile.full_name else none %}

Welcome back{% if welcome_name %}, {{ welcome_name }}{% endif %}! Browse {{ pagination.total }} verified campus listing{{ '' if pagination.total == 1 else 's' }} available right now.

{% endif %} {# Premium nudge: shown to members with no featured listing. Dismissible per session (sessionStorage) so it never nags. #} {% if premium_feature_reminder %} {% endif %} {# Sponsored showcase: the same reusable SaaS banner as the landing page, driven by the real active marketplace ad — only the content differs. #} {% if marketplace_ad %} {% with ad = marketplace_ad %} {% include "advertisements/_ad_showcase.html" %} {% endwith %} {% endif %} {# ---------- Discovery homepage (default, unfiltered view only) ---------- #} {% if discovery %} {% set dp = discovery_premium_ids %}
{# Skeleton shimmer shown only while the root has `is-loading` (removed on DOMContentLoaded); no-JS visitors get the real content straight away. #}
{{ discovery_row('Trending', '🔥', discovery.trending, url_for('main.marketplace', sort='newest'), dp, badge='trending', empty_icon='bi-fire', empty_text='Nothing is trending yet. Be the first to list an item!', cta_label='Sell an item', cta_url=url_for('marketplace.create_listing_view')) }} {# Featured: shown as a carousel when available; when a promoted listing exists but is currently unavailable, show an informative empty state rather than hiding the section. Hidden entirely if nothing is featured. #} {{ discovery_row('Featured', '⭐', discovery.featured, none, dp, badge='featured', empty_icon='bi-star', empty_text=('There are currently no featured listings available. Featured listings will appear here when Premium sellers feature an available item.' if discovery.featured_exists else none)) }} {{ discovery_row('Recommended for you', '❤️', discovery.recommendations, none, dp, empty_icon='bi-stars', empty_text="Browse a few listings and we'll personalize this section for you.", cta_label='Start browsing', cta_url=url_for('main.marketplace', sort='newest')) }} {{ discovery_row('Popular', '📈', discovery.popular_this_week, none, dp, badge='popular', empty_icon='bi-graph-up-arrow', empty_text='No standout listings yet — check back soon.') }} {{ discovery_row('New arrivals', '🆕', discovery.new_arrivals, url_for('main.marketplace', sort='newest'), dp, badge='new', empty_icon='bi-box-seam', empty_text='No listings yet. Be the first to sell on campus!', cta_label='Sell an item', cta_url=url_for('marketplace.create_listing_view')) }} {# Recently viewed is personal history: hidden entirely for anonymous visitors and when the user has no history (no empty-state placeholder). #} {{ discovery_row('Recently viewed', '🕒', discovery.recently_viewed, none, dp) }}
{% endif %} {# ---------- Browse all listings (compact catalog section) ---------- #}
{# Compact header: title on the left, live count on the right #}

{{ 'Browse all listings' if discovery else 'Marketplace' }}

Discover everything currently available on campus.

{{ "{:,}".format(pagination.total) }} listing{{ '' if pagination.total == 1 else 's' }}
{# Browse categories — compact chips, immediately below the header #} {% if discovery and discovery.categories %} {% endif %} {# Compact filter toolbar (same fields, same behaviour) #} {# Active filter chips — each removes just its own filter. #} {% if filter_chips %}
{% for chip in filter_chips %} {{ chip.label }} Remove filter {{ chip.label }} {% endfor %} Clear all
{% endif %}
{% if pagination.items %}
{% for listing in pagination.items %} {{ listing_card(listing, actions=['view_details'], show_status=false, meta=['condition', 'location', 'date'], favorite=true, premium_ids=premium_seller_ids, reputations=reputation_map, badges=badge_map) }} {% endfor %}
{{ render_pagination(pagination, 'main.marketplace', {'q': q or none, 'category': category_id or none, 'condition': condition or none, 'min_price': min_price or none, 'max_price': max_price or none, 'sort': sort, 'seller_rating': seller_rating or none, 'trusted': '1' if trusted_only else none, 'badge': badge or none}) }}
{% elif has_filters %} {% else %} {{ empty_state('bi-bag-plus', 'No listings yet', 'The marketplace is just getting started. Be the first to list a campus item.', cta_label='Create a listing', cta_url=url_for('marketplace.create_listing_view'), cta_icon='bi-plus-lg') }} {% endif %}
{% endblock %} {% block scripts %} {% endblock %}