{% import "helper.twig" as helper %}

<div class="table-responsive">
    <table class="table table-striped table-header table-hover">
        <thead>
        <tr>
            <th>{% trans %}part.supplier.name{% endtrans %}</th>
            <th>{% trans %}part.supplier.partnr{% endtrans %}</th>
            <th></th>
            <th></th>
        </tr>
        </thead>
        <tbody>
        {% for order in part.orderdetails %}
            <tr class="{% if order.obsolete %}table-danger{% endif %}">
                <td>
                    <a href="{{ entity_url(order.supplier, 'list_parts') }}">{{ order.supplier.name }}</a>
                </td>
                <td>{% if order.supplierProductUrl is not empty %}
                        <a href="{{ order.supplierProductUrl }}" rel="noopener" target="_blank" class="link-external">{{ order.supplierPartNr }}</a>
                    {% else %}
                        {{ order.supplierPartNr }}
                    {% endif %}
                </td>
                <td>
                    {% if order.pricedetails is not empty %}
                        <table class="table table-bordered table-sm table-striped table-hover">
                            <thead class="thead-dark">
                            <tr>
                                <th>{% trans %}part.order.minamount{% endtrans %}</th>
                                <th>{% trans %}part.order.price{% endtrans %}</th>
                                <th>
                                    {% trans %}part.order.single_price{% endtrans %}
                                    {% if part.partUnit %}
                                        / 1 {{ part.partUnit.unit }}
                                    {% endif %}
                                </th>
                            </tr>
                            </thead>
                            <tbody>
                            {% for detail in order.pricedetails %}
                                {# @var detail App\Entity\PriceInformations\Pricedetail #}
                                <tr>

                                    <td>
                                        {{ detail.MinDiscountQuantity | format_amount(part.partUnit) }}
                                    </td>
                                    <td>
                                        {{ detail.price | format_money(detail.currency) }} / {{ detail.PriceRelatedQuantity | format_amount(part.partUnit) }}
                                        {% set tmp = pricedetail_helper.convertMoneyToCurrency(detail.price, detail.currency) %}
                                        {% if detail.currency != (app.user.currency ?? null) and tmp is not null and tmp.GreaterThan(0) %}
                                            <span class="text-muted">({{ pricedetail_helper.convertMoneyToCurrency(detail.price, detail.currency, app.user.currency ?? null) | format_money(app.user.currency ?? null) }})</span>
                                        {% endif %}
                                        <small class="text-muted">{{- helper.vat_text(detail.includesVAT) -}}</small>
                                    </td>
                                    <td>
                                        {{ detail.PricePerUnit  | format_money(detail.currency) }}
                                        {% set tmp = pricedetail_helper.convertMoneyToCurrency(detail.PricePerUnit, detail.currency) %}
                                        {% if detail.currency != (app.user.currency ?? null) and tmp is not null and tmp.GreaterThan(0) %}
                                            <span class="text-muted">({{ pricedetail_helper.convertMoneyToCurrency(detail.PricePerUnit, detail.currency, app.user.currency ?? null) | format_money(app.user.currency ?? null) }})</span>
                                        {% endif %}
                                        <small class="text-muted">{{- helper.vat_text(detail.includesVAT) -}}</small>
                                    </td>
                                </tr>
                            {% endfor %}
                            </tbody>
                        </table>
                    {% endif %}
                </td>
                <td> {# Action for order information #}
                    <div class="btn-group">
                        <button type="button" class="btn btn-outline-secondary btn-sm dropdown-toggle" data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                            <i class="fa-solid fa-lightbulb fa-fw"></i>
                        </button>
                        <div class="dropdown-menu">
                            <span class="text-muted dropdown-item-text" ><i class="fas fa-lightbulb fa-fw"></i> <b>ID:</b> {{ order.iD }}</span>
                            <span class="text-muted dropdown-item-text" ><i class="fas fa-history fa-fw"></i> <b>{% trans %}lastModified{% endtrans %}:</b> {{ helper.entity_last_modified(order) }}</span>
                            <span class="text-muted dropdown-item-text" ><i class="fas fa-calendar-plus fa-fw"></i> <b>{% trans %}createdAt{% endtrans %}:</b> {{ helper.entity_created_at(order) }}</span>
                        </div>
                    </div>
                </td>
            </tr>
        {% endfor %}
        </tbody>
    </table>
</div>
