{ifmodule QUANTITY_DISCOUNT}
{if !$product}
   {$product = $body.product}
{/if}

{$variation_id = $product.variationId}
{if !$variation_id}
   {$variation_id = $smarty.get.id_variation}
{/if}

{if !empty($variation_id)}
   {get_quantity_discounts id_product={$product.id} id_variation={$variation_id} assign='quantityDiscounts'}
{else}
   {get_quantity_discounts id_product={$product.id} assign='quantityDiscounts'}
{/if}

{if $quantityDiscounts|count > 1}
   <div class="quantity-discounts-wrapper" data-quantity-discounts="quantityDiscounts">
      <p class="title-default">{t}Slevy při odběru více kusů{/t}</p>

      <div class="quantity-discounts-inner" data-reload="quantityDiscounts">
         <script>
            wpj.quantityDiscounts = [];
         </script>
         {foreach $quantityDiscounts as $quantityDiscount}
            <script>
               wpj.quantityDiscounts.push({
                  price: "{$quantityDiscount.price|format_price}",
                  priceNoVat: "{$quantityDiscount.price->getPriceWithoutVat()|format_price}",
                  piecesFrom: {$quantityDiscount.pieces_from},
                  piecesTo: {$quantityDiscount.pieces_to|default:"undefined"},
                  index: {$quantityDiscount@index}
               });
            </script>
            <div class="quantity-discounts-item {if $quantityDiscount@first}active{/if}"
                 data-quantity-discounts-row="{$quantityDiscount@index}">
               {block "quantity-discounts-item-inner"}
                  <div class="pieces">
                     {$quantityDiscount.pieces_from}
                     {if $quantityDiscount.pieces_to}
                        {if $quantityDiscount.pieces_to != $quantityDiscount.pieces_from} - {$quantityDiscount.pieces_to}{/if}
                        {if findModule('products', 'units_float')}{$product.unit.short_name|lower}{else}{t}ks{/t}{/if}
                     {else}
                        {t}a více{/t}
                     {/if}
                  </div>
                  {if $quantityDiscount.discount->isPositive()}
                      {if $quantityDiscount.discount_type == 'perc'}
                           <span class="discount">{$quantityDiscount.discount->asFloat()|round}%</span>
                      {else}
                           <span class="discount">{$quantityDiscount.discount_value.value_with_vat_no_rounding|format_price}</span>
                      {/if}
                  {/if}
                  <div class="price">
                     <strong>{$quantityDiscount.price|format_price}</strong>&nbsp;/&nbsp;{if $module.PRODUCTS__UNITS_FLOAT}{$product.unit.short_name|lower}{else}{t}ks{/t}{/if}
                  </div>
               {/block}
            </div>
         {/foreach}
      </div>
   </div>
{/if}
{/ifmodule}
