{% load i18n %}
{% for order in orders %}
<tr>
    <td>{{ order.id }}</td>
    <td>
        <div class="row align-center">
            {% if order.user.avatar %}
            <img src="{{ order.user.avatar.url }}" class="circle tiny">
            {% else %}
            <i class="circle tiny">person</i>
            {% endif %}
            <span class="max">{{ order.user.username }}</span>
        </div>
    </td>
    <td>
        {% for item in order.items.all %}
            <div>{{ item.quantity }}x {{ item.recipe.title }}</div>
        {% endfor %}
    </td>
    <td>€ {{ order.total_price }} </td>
    <td>
        <form method="post" action="{% url 'admin_order_update_status' order.pk %}" class="row align-center no-space">
            {% csrf_token %}
            <div class="field border round small no-margin">
                <select name="status" onchange="this.form.submit()" {% if order.status == 'COMPLETED' or order.status == 'CANCELLED' %}disabled{% endif %}>
                    {% for val, label in status_choices %}
                    <option value="{{ val }}" {% if order.status == val %}selected{% endif %}>{{ label }}</option>
                    {% endfor %}
                </select>
                <i>arrow_drop_down</i>
            </div>
            {% if order.status == 'COMPLETED' or order.status == 'CANCELLED' %}
            <span class="chip {% if order.status == 'COMPLETED' %}primary{% else %}error{% endif %} margin">
                {{ order.get_status_display }}
            </span>
            {% endif %}
        </form>
    </td>
    <td>{{ order.created_at|date:"d/m/Y H:i" }}</td>
</tr>
{% empty %}
<tr>
    <td colspan="6" class="center-align">{% trans "No orders found." %}</td>
</tr>
{% endfor %}
