{% extends 'base.html' %}
{% block title %}Confirm Receipt — {{ po.reference }}{% endblock %}

{% block content %}
<div class="flex justify-between items-center mb-6">
  <h1 class="text-2xl font-bold">Confirm Receipt</h1>
  <a href="{% url 'inventory:po_detail' po.pk %}" class="btn btn-ghost btn-sm">← Back</a>
</div>

<div class="card bg-base-100 shadow max-w-lg">
  <div class="card-body">
    <div class="alert alert-warning mb-4">
      <span>
        Confirming receipt will <strong>add stock</strong> for all items
        {% if po.account %}
          and <strong>deduct {{ po.total|floatformat:0 }}</strong>
          from <strong>{{ po.account.name }}</strong>.
        {% endif %}
        This cannot be undone.
      </span>
    </div>

    <table class="table table-sm mb-4">
      <thead>
        <tr><th>Product</th><th>Qty</th><th>Cost</th><th>Total</th></tr>
      </thead>
      <tbody>
        {% for item in po.items.all %}
        <tr>
          <td>{{ item.product.name }}</td>
          <td>{{ item.quantity }}</td>
          <td>{{ item.unit_cost|floatformat:0 }}</td>
          <td>{{ item.line_total|floatformat:0 }}</td>
        </tr>
        {% endfor %}
      </tbody>
    </table>

    <div class="text-right font-bold mb-4">
      Total: {{ po.total|floatformat:0 }}
    </div>

    <form method="post">
      {% csrf_token %}
      <div class="card-actions justify-end">
        <a href="{% url 'inventory:po_detail' po.pk %}" class="btn btn-ghost">Cancel</a>
        <button type="submit" class="btn btn-success">✅ Confirm Receipt</button>
      </div>
    </form>
  </div>
</div>
{% endblock %}