{$closed = $body.payment_id|strpos:"`$payment.id`-" !== 0}

{if !isset($tpl_vars.online_payment_visible_items)}
   {$tpl_vars.online_payment_visible_items = 2}
{/if}

{foreach $object->getAvailableMethods() as $name => $method}
   {$method_id = "`$id`-`$name`"}
   {$method_hidden = $method@iteration > $tpl_vars.online_payment_visible_items and $closed
   and $object->getAvailableMethods()|count > $tpl_vars.online_payment_visible_items + 1}
   <div class="cart-box-row payment-item payment-item-{$name|lower|strip_accent}
      {if $method_hidden}hidden" style="display: none;{/if}"
      data-tracking-click-delivery-type='{get_gtm_data encode=true type='ecommerce' method='AddPaymentInfo' data=['payment' => $payment]}'>
      <label for="pay{$method_id}" class="delivery-content custom-radio custom-control">
         <input type="radio" name="payment_id" value="{$method_id}" id="pay{$method_id}"
                class="custom-control-input" {$body.payment_id|checked:$method_id nofilter}>
         <span class="custom-control-indicator"></span>
         <span class="img"><img src="{$method.image}" style="width: 75px; height: auto;"
                                title="{$method.name}" alt="{$method.name}"></span>
         <span class="name">{block "method-name"}{$method.name}{/block}</span>
         <span class="price">
            <span data-reload="payment_price_{$method_id}">
               {block "payment-price"}
                  {$paymentPrice = $view->getPaymentPrice($id)}
                  {if $paymentPrice && $paymentPrice.value_with_vat->isPositive()}
                     {$paymentPrice.value_with_vat|format_price}
                  {else}
                     {t}zdarma{/t}
                  {/if}
               {/block}
             </span>
          </span>
      </label>
   </div>
   {if $method@index == $tpl_vars.online_payment_visible_items and $closed and !$method@last}
      <div class="cart-box-row payment-item thepay-method payments-list">
         <p>
            <strong>{$payment.name}</strong>
            {t}Vyberte si z možností platby online.{/t}
         </p>
         <div class="payment-logos">
            {foreach $object->getAvailableMethods() as $name => $method}
               {if $method@index >= $tpl_vars.online_payment_visible_items}
                  <img src="{$method.image}" title="{$method.name}" alt="{$method.name}"
                       style="max-width: 60px; height: auto;" class="payment-item-small">
               {/if}

               {if $method@iteration == $tpl_vars.online_payment_visible_items + 3}
                  {break}
               {/if}
            {/foreach}
         </div>
         <a href="" id="thepay20-more" class="more" title="{t}Zobrazit více platebních metod{/t}">{t}vybrat platbu{/t}</a>
      </div>
   {/if}
{/foreach}

<script>
   wpj.onReady.push(function() {
      $('body').on('click', '#thepay20-more', function() {

         $(this).closest('.payments-list').hide();
         $('.payment-item.hidden').removeClass('hidden').fadeIn();

         return false;
      });
   });
</script>
