{% trans_default_domain 'products' %}
{% macro orderItem(this, item, class = '', show_image = true, show_price = true) %}
   <div class="product {{ class }}">
      {% if item.itemType == 'gift' and item.note.set_info is not defined %}
         <div class="set-label">{{ 'products.added.gift'|trans }}</div>
      {% endif %}
      {% if show_image %}
         <div class="image">
            {% if item.productId and item.thumbnail %}
               <a href="{{ item.url }}" title="{{ 'products.show'|trans }}">
                  <twig:Picture class="img-responsive" thumbnail="{{ item.thumbnail }}" type="product_cart"/>
               </a>
            {% endif %}
         </div>
      {% endif %}
      <div class="title">
         {% if item.productId %}
            <a href="{{ item.url }}" title="{{ 'products.show'|trans }}">{{ item.productTitle }}</a>
            <span class="variation">{{ item.variation_title ?? '' }}</span>
         {% else %}
            {{ item.descr }}
         {% endif %}

         {% if item.product is defined and item.note %}
            {% set itemInfo = this.getItemInfo(item) %}
            {% for key, print_note in itemInfo %}
               {% if print_note is not iterable %}
                  <span class="variation">{{ print_note }}</span>
               {% endif %}
            {% endfor %}
         {% endif %}

         {% if this.coupons(item.id) %}
            <br>Kód:
            {% for code, url in this.coupons(item.id) %}
               <a href="{{ url }}" target="_blank">{{ code }}</a>{% if not loop.last %},{% endif %}
            {% endfor %}
         {% endif %}
      </div>

         {% if show_price %}
            <div class="total">
               <div class="pieces">
                  {% if this.isPreorder %}
                     {{ item.pieces_sent }} {{ 'jsMultisets.ks'|trans([], 'others') }}
                     /
                  {% endif %}
                  {% if item.productId %}
                     {{ item.pieces }} {{ 'jsMultisets.ks'|trans([], 'others') }}
                  {% endif %}
               </div>

               <div class="price">
                  {% if item.totalPrice.value == '0' %}
                     {{ 'price.free'|trans }}
                  {% else %}
                     {% if this.isPreorder or this.showPriceWithoutVat %}
                        {{ item.totalPrice|formatPrice(withVat: false, ceil: false) }} {{ 'variations.priceWithoutVat'|trans }}
                     {% else %}
                        {{ item.totalPrice|formatPrice(withVat: true, ceil: false) }}
                     {% endif %}
                  {% endif %}
               </div>
            </div>
         {% endif %}
   </div>
{% endmacro %}

<div {{ attributes }}>
   {% if this.isPreorder %}
      <div class="items-header">
         <p class="title-default">{{ this.title|default('items.title'|trans) }}</p>
         <p class="title-default">{{ this.title|default('items.title.pieces'|trans) }}</p>
      </div>
   {% else %}
      <p class="title-default">{{ this.title|default('items.title'|trans) }}</p>
   {% endif %}

   {% for product in this.items %}
      {{ _self.orderItem(this, product, product.itemType in ['gift', 'orders_charge'] ? 'additional-item' : '') }}

      {% for item in product.additionalItems ?? [] %}
         {{ _self.orderItem(this, item, 'additional-item additional-item-' ~ item.itemType, item.itemType in ['orders_charge'] ? false : true, item.itemType in ['gift'] ? false : true) }}
      {% endfor %}
   {% endfor %}
</div>
