{extends "returns/returns-new.tpl"}

{block content}
   {if $body.items}
      <div class="bg-alt">
          {insert_page type="RETURN_PRODUCTS" use_default=1 assign="page"}
          {$page.blocks[0].content nofilter}
      </div>
      <p>{t}Vyberte produkty, které chcete vrátit.{/t}</p>
      <form name="items-form" method="post">
         {foreach $body.items|regroup:'id_order' as $order}
            {$first = $order|reset}
            <table class="table table-orders table-reclamations {if $view->getOrderId() != $order.id}closed{/if}" data-returns>
               <tr>
                  <th class="checkbox-column">
                     <label for="order_{$order.id}" class="custom-control custom-checkbox">
                        <input class="custom-control-input" type="checkbox" name="order[]" id="order_{$order.id}"
                               value="{$order.id}" {if $body.allItemsSelected.$order.id}checked{/if} data-order-check>
                        <span class="custom-control-indicator"></span>
                     </label>
                  </th>
                  <th colspan="3">{t}č.{/t} {$first.order_no} ({$first.delivery_date|format_date_locale_pretty:'d. L. Y'})</th>
                  <th class="pieces-column">{t}ks{/t} <span class="fc icons_arrow_down"></span></th>
               </tr>
               {foreach $order as $idItem => $item}
                  {change_currency currency=$item.currency}
                     <tr>
                        <td>
                           <label for="item_{$idItem}" class="custom-control custom-checkbox">
                              {*<input class="custom-control-input" type="checkbox" name="items[]" id="item_{$idItem}"
                                     value="{$item.id}" {if $item.selected}checked{/if} data-row-check>*}
                              <input class="custom-control-input" type="checkbox" name="return_items[{$item.id}][item]" id="item_{$idItem}"
                      value="{$item.id}" {if $item.selected}checked{/if} data-row-check>
                              <span class="custom-control-indicator"></span>
                           </label>
                        </td>
                        <td>{$item.pieces}&nbsp;x</td>
                        <td>
                           <a target="_blank"
                              href="{path('kupshop_content_redirect_redirect', ['type' => 'product', 'id' => $item.id_product])}">
                              {$item.descr}
                           </a>
                        </td>
                        <td><span class="price">{$item.piece_price_with_vat|format_price}</span></td>
                        <td>
                           <div class="pieces-wrapper">
                              {$step = $item.product.unit.step|default:1}
                              {ifmodule PRODUCTS__STEP}
                              {$data = $item.product->getData()}
                              {$step = $data.step|default:$step}
                              {/ifmodule}

                              {if $body.returns.return_items[{$item.id}].pieces}
                                 {$pieces = $body.returns.return_items[{$item.id}].pieces}
                              {else}
                                 {$pieces = $item.returnable_pieces}
                              {/if}
                              <div class="submit-block">
                                 {*<input type="number" name="return_items[{$idItem}][pieces]" id="return_items_{$idItem}" class="form-control"
                                        value="{if $item.selected}{$body.return_items[$idItem]}{/if}"
                                        max="{$item.returnable_pieces}" min="0" size="2" data-pieces {if !$item.selected}disabled{/if}>
*}
                                 <input type="hidden" name="return_items[{$item.id}][id_product]" value="{$item['id_product']}">
                                 <input type="number" name="return_items[{$item.id}][pieces]" id="return_items_{$idItem}"
                                     value="{if $item.selected}{$pieces|string_format:"%.{$item.product.unit.pieces_precision|default:0}f"}{/if}"
                                     class="form-control disable-spinner" step="{$step}" min="{$step}" max="{$item.returnable_pieces}"
                                     data-buy_count="input" data-pieces
                                     {if $module.PRODUCTS__UNITS_FLOAT}
                                        data-precision="{$item.product.unit.pieces_precision|default:0}"
                                     {/if}
                                 >
                                 <div class="buy_count">
                                    {*<button type="button" class="fc fc-angle-up plus_unit" data-cart="plus"></button>
                                    <button type="button" class="fc fc-angle-down minus_unit" data-cart="minus"></button>*}
                                    <button type="button" class="fc fc-angle-up plus_unit" title="{t mnozstvi=$step}Přidat {mnozstvi} ks{/t}"
                                    {if $pieces > $item.returnable_pieces}disabled{/if} data-cart="plus"></button>
                                    <button type="button" class="fc fc-angle-down minus_unit" title="{t mnozstvi=$step}Odebrat {mnozstvi} ks{/t}"
                                    {if $pieces <= $step}disabled{/if} data-cart="minus"></button>
                                 </div>
                              </div>
                           </div>
                        </td>
                     </tr>
                  {/change_currency}
               {/foreach}
            </table>
         {/foreach}

         <div class="row">
            <div class="col-md-6">
               <a href="{path('kupshop_returns_returns_returns')}" class="btn btn-prevstep btn-gray">
                  {t}Zpět na seznam odstoupení{/t}
               </a>
            </div>
            <div class="col-md-6 text-right">
               <button type="submit" name="nextStep" value="1" class="btn btn-primary">
                  <strong>{t}Pokračovat{/t}</strong>
               </button>
            </div>
         </div>
      </form>
   {else}
      {* @formatter:off *}
      <p>{t}Aktuálně nemáte zakoupený žádný produkt, který by bylo možné vrátit.{/t}</p>
      <p>{t escape=false email=$dbcfg.shop_email phone=$dbcfg.shop_phone}Pokud se domníváte, že se jedná o omyl, neváhejte nás kontaktovat
            na emailu <strong><a href="mailto:{email}">{email}</a></strong>.{/t}</p>
      {* @formatter:on *}
      <a href="{path('kupshop_returns_returns_returns')}" class="btn btn-prevstep btn-gray">
         {t}Zpět na seznam odstoupení{/t}
      </a>
   {/if}
{/block}

{block "js-dynamic-load" append}
   {asset_compile}
      <script src="/static/js/wpj.reclamation.js"></script>
   {/asset_compile}
{/block}
