{extends "focus/focus.base.tpl"}

{block "focus-class"}focus-quick-buy{/block}
{block "focus-header"}{/block}

{block "focus-content"}
   <a href="#" class="focus-close" data-focus="close">
      <span>{t}zavřít{/t}</span> <span class="fc lightbox_close"></span>
   </a>
   {get_unified_product id_product=$body.productId assign="product"}
   {$product.product->fetchVariations(true)|silent}
   <div class="row" data-quickbuy-wrapper>
      <div class="col-md-6 col-xxs-12">
         <div class="img">
            <img src="{get_photo photo=$product.image size='product_catalog'}"
                 width="{$cfg.Photo.types.product_catalog.size[0]}" height="{$cfg.Photo.types.product_catalog.size[1]}"
                 class="img-responsive" alt="{$product.title}" data-quickbuy-image>
         </div>
      </div>
      <div class="col-md-6 col-xxs-12">
         <p class="h3">{$product.title}</p>
         <div class="product-data">
            {if $product.product.idProducer}
               {get_producer id_producer=$product.product.idProducer assign='producer'}
               <p>{t}Výrobce:{/t} <a href="{url s=category IDpd=$product.product.idProducer}">{$producer.name}</a></p>
            {/if}
            {if $product.code}<p>{t}Kód:{/t} {$product.code}</p>{/if}
         </div>
         {if $product.product.descr}
            <p class="product-annotation">{$product.product.descr nofilter}</p>
         {/if}

         <form action="{url s=cart}" method="get" data-buy-form class="catalog-buy-form">
            <input type="hidden" name="act" value="add">
            <input type="hidden" value="1" name="redir">
            <input type="hidden" name="IDproduct" value="{$product.id}">
            <input type="hidden" name="IDvariation" value="285">
            <input type="hidden" name="No" value="1">

            {include "components/block.quick-buy.variations.tpl" variations=$product.product.variations.variations}
            {foreach $product.product.variations.variations as $var}
               {calc_product_discount product=$product variation=$var assign='discount'}
               <div class="product-price-block">
                  <p class="price" data-quickbuy-price>{$var.productPrice|format_price}</p>
                  {if $discount.discount->asFloat() >= 1}
                     <p class="price-common" data-quickbuy-price-common>{$discount.priceOriginal|format_price}</p>
                  {/if}
               </div>
               {break}
            {/foreach}


            <button type="submit" class="btn btn-primary btn-insert btn-block" data-quickbuy-submit data-submit-btn{if $dbcfg.analytics.google_tag_manager.active_fe_events == 'Y'} data-tracking-clickAddToCart='{get_gtm_data encode=true type='ecommerce' method='ClickAddToCart' data=['product' => $product, 'listType' => $listType, 'listId' => $listId]}'{/if}>
               {t}Vložit do košíku{/t}

               {if $product.variations.variations|count}
                  <span class="non-variation" data-variation-error>{t}Vyberte variantu{/t}</span>
               {/if}
            </button>
         </form>
         <a href="{url s=product IDproduct=$product.id TITLE=$product.title}" class="btn btn-secondary btn-block">{t}Přejít na produkt{/t}</a>
      </div>
   </div>
   <script>
      $('[data-variations-quickbuy] input:checked').each(function () {
         let $this = $(this);
         let wrapper = $this.closest('[data-quickbuy-wrapper]');
         let img = $this.data('var-image');

         if (img) {
            wrapper.find('[data-quickbuy-image]').attr('src', img);
         }
      });
   </script>
{/block}
