{% macro participant_identity(offer, current_user, conversation, size='md') -%} {% set identity_class = 'participant-buyer' %} {% set role_label = 'Buyer' %} {% set display_name = 'You' %} {% if offer %} {% if offer.buyer_id == current_user.id %} {% set identity_class = 'participant-buyer' %} {% set role_label = 'Buyer' %} {% set display_name = 'You' %} {% elif offer.seller_id == current_user.id %} {% set identity_class = 'participant-seller' %} {% set role_label = 'Seller' %} {% set display_name = 'You' %} {% elif conversation and offer.buyer_id is not none and offer.buyer_id == conversation.buyer_id %} {% set identity_class = 'participant-buyer' %} {% set role_label = 'Buyer' %} {% set display_name = (offer.buyer.profile.full_name if offer.buyer and offer.buyer.profile and offer.buyer.profile.full_name else offer.buyer.email if offer.buyer else (conversation.buyer.profile.full_name if conversation.buyer and conversation.buyer.profile and conversation.buyer.profile.full_name else conversation.buyer.email if conversation.buyer else 'Participant')) %} {% elif conversation and offer.seller_id is not none and offer.seller_id == conversation.seller_id %} {% set identity_class = 'participant-seller' %} {% set role_label = 'Seller' %} {% set display_name = (offer.seller.profile.full_name if offer.seller and offer.seller.profile and offer.seller.profile.full_name else offer.seller.email if offer.seller else (conversation.seller.profile.full_name if conversation.seller and conversation.seller.profile and conversation.seller.profile.full_name else conversation.seller.email if conversation.seller else 'Participant')) %} {% elif offer.buyer_id is not none %} {% set identity_class = 'participant-buyer' %} {% set role_label = 'Buyer' %} {% set display_name = (offer.buyer.profile.full_name if offer.buyer and offer.buyer.profile and offer.buyer.profile.full_name else offer.buyer.email if offer.buyer else 'Participant') %} {% else %} {% set identity_class = 'participant-seller' %} {% set role_label = 'Seller' %} {% set display_name = (offer.seller.profile.full_name if offer.seller and offer.seller.profile and offer.seller.profile.full_name else offer.seller.email if offer.seller else 'Participant') %} {% endif %} {% endif %} {% set initial = (display_name[0] if display_name else 'P') %}
{{ display_name }} ({{ role_label }})
{%- endmacro %} {% set offers = conversation.offers|sort(attribute='created_at', reverse=true) if conversation and conversation.offers else [] %} {% set latest_offer = offers[0] if offers else none %} {% set mine = latest_offer.buyer_id == current_user.id if latest_offer is not none else False %} {% set is_receiver = latest_offer.seller_id == current_user.id if latest_offer is not none else False %} {% set status_label = latest_offer.status.value|title if latest_offer is not none else 'Pending' %} {% set badge_class = 'text-bg-warning text-dark' %} {% if latest_offer and latest_offer.status.value == 'accepted' %} {% set badge_class = 'text-bg-success' %} {% elif latest_offer and latest_offer.status.value == 'rejected' %} {% set badge_class = 'text-bg-danger' %} {% elif latest_offer and latest_offer.status.value == 'countered' %} {% set badge_class = 'text-bg-primary' %} {% elif latest_offer and latest_offer.status.value == 'pending' %} {% set badge_class = 'text-bg-warning text-dark' %} {% endif %} {% set bargaining_disabled = conversation and conversation.listing and conversation.listing.status.value != 'available' %} {% set is_pending = latest_offer and latest_offer.status.value == 'pending' %} {% set can_accept = is_pending and is_receiver and not bargaining_disabled %} {% set can_reject = is_pending and is_receiver and not bargaining_disabled %} {% set can_counter = is_pending and is_receiver and not bargaining_disabled %}
Current Offer
{% if latest_offer %}
{{ latest_offer.amount }} {{ currency_symbol|default('') }}
{{ participant_identity(latest_offer, current_user, conversation, 'lg') }}
{{ status_label }}
{{ latest_offer.created_at.strftime('%d %b %Y • %H:%M') }}
{% if latest_offer.optional_message %}
{{ latest_offer.optional_message }}
{% endif %} {% if conversation and conversation.listing %}
{{ conversation.listing.status.value|title }}
{% endif %} {% else %}
No negotiation has started yet.
{% endif %}
{% if latest_offer and latest_offer.status.value == 'accepted' %}
Offer accepted. You may continue chatting to arrange payment and pickup.
{% elif bargaining_disabled %}
Bargaining is no longer available for this listing.
{% endif %} {% if can_accept or can_reject or can_counter %}
Actions
{% if can_accept %}
{% endif %} {% if can_reject %}
{% endif %} {% if can_counter %} {% endif %}
{% endif %} {% if can_counter %}
Make a Counter Offer
{% if offer_form is defined %}{{ offer_form.hidden_tag() }}{% endif %}
{% endif %} {% if offers %}
Offer History
{% for offer in offers %} {% set history_badge_class = 'text-bg-warning text-dark' %} {% if offer.status.value == 'accepted' %} {% set history_badge_class = 'text-bg-success' %} {% elif offer.status.value == 'rejected' %} {% set history_badge_class = 'text-bg-danger' %} {% elif offer.status.value == 'countered' %} {% set history_badge_class = 'text-bg-primary' %} {% endif %}
{{ offer.amount }} {{ currency_symbol|default('') }}
{{ offer.status.value|title }}
{{ participant_identity(offer, current_user, conversation) }}
{% if offer.optional_message %}
{{ offer.optional_message }}
{% endif %}
{{ offer.created_at.strftime('%d %b %Y • %H:%M') }}
{% endfor %}
{% endif %}