{% extends "base.j2" -%}

{%- block append_to_head_tag_section %}
  <title>Offers &mdash; {{ shop.name }}</title>
{%- endblock %}

{% block content %}
<section class="one-column shop-offers-page">

  <div class="well">
    <h1 class="type-title">Offers for {{ shop.name }}</h1>
    <p class="profile-meta">
      {% if open_count %}{{ open_count }} open{% if open_count != offers|length %} of {{ offers|length }} total{% endif %}.{% else %}No open offers.{% endif %}
    </p>
  </div>

  {% if offers %}
  <div class="well">
    <table class="shop-offers-table">
      <thead>
        <tr>
          <th>Product</th>
          <th class="col-narrow">Buyer</th>
          <th class="col-narrow">Amount</th>
          <th class="col-narrow">Round</th>
          <th class="col-narrow">State</th>
          <th class="col-narrow">Last action</th>
          <th class="col-action"></th>
        </tr>
      </thead>
      <tbody>
        {% for o in offers %}
        <tr class="{% if o.waiting_on_seller %}offer-row-needs-action{% elif o.is_terminal %}offer-row-terminal{% endif %}">
          <td>{{ o.product_title }}</td>
          <td class="col-narrow">{% if o.buyer_handle %}<a href="/profile/{{ o.buyer_handle }}?shop={{ shop.id }}">{{ o.buyer_name }}</a>{% else %}{{ o.buyer_name }}{% endif %}</td>
          <td class="col-narrow">${{ "%.2f"|format(o.current_amount) }}</td>
          <td class="col-narrow">{{ o.round_count }}</td>
          <td class="col-narrow">
            <span class="offer-state-badge offer-state-{{ o.state }}">{{ o.state_human }}</span>
            {% if o.waiting_on_seller %}<span class="offer-row-flag">your turn</span>{% endif %}
          </td>
          <td class="col-narrow">{{ o.last_action_human }}</td>
          <td class="col-action"><a href="/o/{{ o.id }}" class="mps-button-small">View</a></td>
        </tr>
        {% endfor %}
      </tbody>
    </table>
  </div>
  {% else %}
  <div class="well">
    <p>No one has made an offer on a product in this shop yet. When they do, the negotiation shows up here &mdash; and you get an email.</p>
  </div>
  {% endif %}

</section>
{% endblock %}
