{#**
 * Copyright since 2007 PrestaShop SA and Contributors
 * PrestaShop is an International Registered Trademark & Property of PrestaShop SA
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Open Software License (OSL 3.0)
 * that is bundled with this package in the file LICENSE.md.
 * It is also available through the world-wide-web at this URL:
 * https://opensource.org/licenses/OSL-3.0
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@prestashop.com so we can send you a copy immediately.
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade PrestaShop to newer
 * versions in the future. If you wish to customize PrestaShop for your
 * needs please refer to https://devdocs.prestashop.com/ for more information.
 *
 * @author    PrestaShop SA and Contributors <contact@prestashop.com>
 * @copyright Since 2007 PrestaShop SA and Contributors
 * @license   https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
 *#}

<div class="card" data-role="cart-summary">
  <h3 class="card-header">
    {{ 'Cart summary'|trans({}, 'Admin.Orderscustomers.Feature') }}
  </h3>
  <div class="card-body">
    <table class="table">
      <thead>
        <tr>
          <th>&nbsp;</th>
          <th>{{ 'Product'|trans({}, 'Admin.Global') }}</th>
          <th>{{ 'Unit price'|trans({}, 'Admin.Global') }}</th>
          <th>{{ 'Quantity'|trans({}, 'Admin.Global') }}</th>
          <th>{{ 'Stock'|trans({}, 'Admin.Global') }}</th>
          <th>{{ 'Total'|trans({}, 'Admin.Global') }}</th>
        </tr>
      </thead>
      <tbody>
        {% for product in cartView.cartSummary.products %}
          {% if product.customization is not empty %}
            <tr>
              <td>{{ product.image|raw }}</td>
              <td>
                <a href="{{ path('admin_product_form', {'id': product.id}) }}">
                  {{ product.name }}

                  {% if product.attributes %}
                    <br> {{ product.attributes }}
                  {% endif %}
                  <br>

                  {% if product.reference %}
                    {{ 'Ref:'|trans({}, 'Admin.Orderscustomers.Feature') }}
                    {{ product.reference }}
                  {% endif %}

                  {% if product.reference and product.supplier_reference %}
                    / {{ product.supplier_reference }}
                  {% endif %}
                </a>
              </td>
              <td>{{ product.unit_price_formatted }}</td>
              <td>{{ product.quantity }}</td>
              <td>{{ product.stock_quantity }}</td>
              <td>{{ product.total_price_formatted }}</td>
            </tr>

            <tr>
              <td colspan="2">
                {% for customizationField in product.customization.fields %}
                  <div class="row">
                    <div class="col-6 text-right">
                      {% if customizationField.name %}
                        <strong>{{ customizationField.name }}</strong>
                      {% else %}
                        <strong>{{ 'Text #'|trans({}, 'Admin.Orderscustomers.Feature') }}</strong>
                      {% endif %}
                    </div>
                    <div class="col-6">
                      {% if customizationField.type == 'customizable_file' %}
                        <img src="{{ customizationField.image }}">
                      {% else %}
                        {{ customizationField.value }}
                      {% endif %}
                    </div>
                  </div>
                {% endfor %}
              </td>

              <td></td>
              <td>{{ product.customization.quantity }}</td>
              <td></td>
              <td></td>
            </tr>
          {% endif %}

          {% if product.customization is empty or product.cart_quantity > product.customization_quantity %}
            <tr>
              <td>{{ product.image|raw }}</td>
              <td>
                <a href="{{ path('admin_product_form', {'id': product.id}) }}">
                  {{ product.name }}

                  {% if product.attributes %}
                    <br> {{ product.attributes }}
                  {% endif %}
                  <br>

                  {% if product.reference %}
                    {{ 'Ref:'|trans({}, 'Admin.Orderscustomers.Feature') }}
                    {{ product.reference }}
                  {% endif %}

                  {% if product.reference and product.supplier_reference %}
                    / {{ product.supplier_reference }}
                  {% endif %}
                </a>
              </td>
              <td>{{ product.unit_price_formatted }}</td>
              <td>{{ product.cart_quantity }}</td>
              <td>{{ product.stock_quantity }}</td>
              <td>{{ product.total_price_formatted }}</td>
            </tr>
          {% endif %}
        {% endfor %}

        <tr>
          <td colspan="5">{{ 'Total cost of products:'|trans({}, 'Admin.Orderscustomers.Feature') }}</td>
          <td class="text-right">{{ cartView.cartSummary.total_products_formatted }}</td>
        </tr>

        {% if cartView.cartSummary.total_discounts %}
          <tr>
            <td colspan="5">{{ 'Total value of vouchers:'|trans({}, 'Admin.Orderscustomers.Feature') }}</td>
            <td class="text-right">{{ cartView.cartSummary.total_discounts_formatted }}</td>
          </tr>
        {% endif %}

        {% if cartView.cartSummary.total_wrapping %}
          <tr>
            <td colspan="5">{{ 'Total cost of gift wrapping:'|trans({}, 'Admin.Orderscustomers.Feature') }}</td>
            <td class="text-right">{{ cartView.cartSummary.total_wrapping_formatted }}</td>
          </tr>
        {% endif %}

        {% if cartView.cartSummary.total_shipping %}
          <tr>
            <td colspan="5">{{ 'Total shipping costs:'|trans({}, 'Admin.Orderscustomers.Feature') }}</td>
            <td class="text-right">{{ cartView.cartSummary.total_shipping_formatted }}</td>
          </tr>
        {% endif %}

        <tr>
          <td colspan="5">
            <strong>{{ 'Total'|trans({}, 'Admin.Global') }}</strong>
          </td>
          <td class="text-right">
            <strong>{{ cartView.cartSummary.total_formatted }}</strong>
          </td>
        </tr>
      </tbody>
    </table>

    {% if cartView.cartSummary.cart_rules is not empty %}
      <table class="table">
        <thead>
        <tr>
          <th>{{ 'ID'|trans({}, 'Admin.Global') }}</th>
          <th>{{ 'Discount name'|trans({}, 'Admin.Orderscustomers.Feature') }}</th>
          <th class="text-right">{{ 'Value'|trans({}, 'Admin.Global') }}</th>
        </tr>
        </thead>
        <tbody>
          {% for cartRule in cartView.cartSummary.cart_rules %}
            <tr>
              <td>{{ cartRule.id }}</td>
              <td>
                <a href="{{ getAdminLink('AdminCartRules', true, {
                  id_cart_rule: cartRule.id,
                  updatecart_rule: 1
                }) }}">
                  {{ cartRule.name }}
                </a>
              </td>
              <td class="text-right">
                {% if cartRule.is_free_shipping %}
                  {{ 'Free shipping'|trans({}, 'Admin.Shipping.Feature') }}
                {% else %}
                  - {{ cartRule.formatted_value }}
                {% endif %}
              </td>
            </tr>
          {% endfor %}
        </tbody>
      </table>
    {% endif %}

    <div class="alert alert-warning" role="alert">
      <p class="alert-text">
        {{ 'For this particular customer group, prices are displayed as:'|trans({}, 'Admin.Orderscustomers.Notification') }}
        <strong>
          {% if cartView.cartSummary.is_tax_included %}
            {{ 'Tax included'|trans({}, 'Admin.Global') }}
          {% else %}
            {{ 'Tax excluded'|trans({}, 'Admin.Global') }}
          {% endif %}
        </strong>
      </p>
    </div>
  </div>
</div>
