<div class="catalog-wrapper-top10">

   {get_stats type='free_delivery' assign='free_delivery'}

   {$products->fetchPhotos(2, ['N', 'K', 'V', 'O'])}

   {foreach $products as $product}
      {if $product.id < 0}{continue}{/if}

      <div class="catalog-top10" id="prod-{$product@iteration}">
         {get_ratings assign=ratings id_product=$product.id}

         {assign var='hash' value="#`$product.id`"}

         {block discountSum}
            {$display_discount = $product.display_discount->asFloat()}
            {$product_discount = $product.discount->asFloat()}

            {if $dbcfg.increase_discount >= 1}
               {$display_discount = $display_discount + $dbcfg.increase_discount}
            {/if}

            {$discountSum = 0}

            {if $product_discount > 0 or $display_discount > 0}
               {$discountSum = $product_discount}

               {if $display_discount > 0}
                  {$discountBase = 1 - ($product_discount / 100)}
                  {$discountSum =  ($display_discount * $discountBase) + $product_discount}  {*mame-li 20% slevu, discount bude 0.8*}
               {/if}
            {/if}
         {/block}

         <div class="product-link {if !$product.image.id}noimage{/if}" title="{$product.title}">

            {if !empty($product.modelProducts)}
               {get_prices_sizes_etc modelProducts=$product.modelProducts assign=additional_info}
               {$product.additional_info=$additional_info}
            {/if}

            <a href="{get_photo photo=$product.image size=0}" title="{$product.title}" data-rel="{$product.id}"
               data-gallery>
               <img src="{get_photo photo=$product.image size=3}" alt="{$product.title}"
                    class="img-responsive">
            </a>

            {*
               'Y' => 'Hlavní produkt',
               'N' => 'Hlavní varianta',
               'K' => 'Krabička',
               'G' => '360°',
               'V' => 'Vedlejší varianta',
               'O' => 'Odstín',
             *}

            {$sorted_photos = $product.photos|sort_photos:['V', 'Y', 'K',  'G']}

            <div class="gallery">
                {if $sorted_photos|count>1}
               {foreach $sorted_photos|array_slice:0:2 as $photo}
                  <a href="{get_photo photo=$photo size=0}" title="{$product.title}" data-rel="{$product.id}"
                     data-gallery>
                     <img src="{get_photo photo=$photo size=4}" alt="{$product.title}" class="img-responsive">
                  </a>
               {/foreach}
               {/if}
            </div>

            {$shade_photo = $product.photos|sort_photos:['O']}

            {if $shade_photo}
               <div class="shade">
                  {foreach $shade_photo as $photo}
                     <a href="{get_photo photo=$photo size=0}" title="{$product.title}" data-rel="{$product.id}"
                        data-gallery>
                        <img src="{get_photo photo=$photo size=13}" alt="{$product.title}" class="img-responsive">
                     </a>
                  {/foreach}
               </div>
            {/if}

            <div class="catalog-flags flags">
               {block "top-ten-product-flags"}
                  {$campaigns = getCampaigns()}

                  <span class="flag flag-top10">{$cfg.Sections.Flags['TT'].show_name|default:"{t}Top 10{/t}"}</span>

                  {if $product.campaign_codes.Z or ($free_delivery and $additional_info.prices.min > $free_delivery and !$product->isVirtual())}
                     <span class="flag flag-delivery" title="{t}Doprava zdarma{/t}"><i class="fc icons_free_delivery"></i></span>
                  {/if}

                  {if $product.campaign_codes.N}
                     <i class="flag flag-new">{t}Nové{/t}</i>
                  {/if}

                   {foreach $product.campaign_codes as $flag}
                       {if $flag.catalog_class}
                          <span class="flag flag-{$flag.catalog_class}">{$flag.singular}</span>
                       {/if}
                   {/foreach}

                  {if $discountSum|round >= 3 and $product.producer.data.hidePriceLineThrough != "Y"}
                     <span class="flag flag-discount {if $dbcfg.black_friday == true and $product.campaign_codes.BF}flag-blackfriday{/if}">-{$discountSum|round}%</span>
                  {/if}
               {/block}
            </div>

            {$gender = $product.sex}
            {if $gender}
               <div class="gender">
                  {if $gender == 'W'}
                     <span class="gender-female">{t}Pro ženy{/t} <i class="fc icons_female"></i></span>
                  {elseif $gender == 'M'}
                     <span class="gender-male">{t}Pro muže{/t} <i class="fc icons_male"></i></span>
                  {elseif $gender == 'U'}
                     <span class="gender-unisex">{t}Unisex{/t} <i class="fc icons_unisex"></i></span>
                  {elseif $gender == 'K'}
                     <span class="gender-child">{t}Pro děti{/t} <i class="fc icons_child-gender"></i></span>
                  {/if}
               </div>
            {/if}
         </div>

         <a href="{url s=product IDmodel=$product.model_old_id TITLE=$product.model_title}{$hash}" class="title">
            {$product.model_short_title}
         </a>

         <div class="subtitle-wrapper">
            <p class="subtitle">
               {$product.model_section}
               {if $additional_info.size|count and $product.modelProducts|count}
                  {foreach $additional_info.size as $size}{$size}{if !$size@last}<i> | </i>{/if}{/foreach}
               {else}
                  {$product.title|replace:$product.model_title:''}
               {/if}
            </p>

            {if $ratings.rating_count >= 5}
               {$stars = $ratings.rating|round}
               <div class="nowrap">
                  <span class="number-stars rating-{$stars}" title="{t}Hodnocení{/t} {$ratings.rating|format_float:-1}
                     {t plural="hvězdičky" plural5="hvězdiček" count=$stars}hvězdička{/t}">
                     <i class="fc icons_star"></i>
                     <i class="fc icons_star"></i>
                     <i class="fc icons_star"></i>
                     <i class="fc icons_star"></i>
                     <i class="fc icons_star"></i>
                  </span>
                  <small>{$ratings.rating_count} {t plural="hodnocení" plural5="hodnocení" count=$ratings.rating_count}hodnocení{/t}</small>
               </div>
            {/if}
         </div>

         {function sumDiscount}
            {* skrtlou cenu nezobrazovat u modelu *}
            {if $discountSum|round >= 3 and $product.producer.data.hidePriceLineThrough != "Y"}
               {$discount =  1 - ($product_discount / 100) } {* mame-li 20% slevu, discount bude 0.8 *}
               {$beforeDiscount = ($product.price_array.value_with_vat->asFloat() / $discount)} {* cena pred slevou *}

               {* pokud je sleva i u varianty, cena pred slevou se vypocita jeste jednou *}
               {if $display_discount > 0}
                  {$discount =  1 - ($display_discount/ 100)}
                  {$beforeDiscount = ($beforeDiscount / $discount)}
               {/if}

               {block priceTranslation}
                  {$commonPriceTranslation = "{t}Běžná cena{/t}"}
               {/block}

               {if $beforeDiscount|format_price == $product.price_array|format_price}
                  <span class="strike-price">{$commonPriceTranslation} <del>{$beforeDiscount|format_price:"ceil=no"}</del></span>
               {else}
                  <span class="strike-price">{$commonPriceTranslation} <del>{$beforeDiscount|format_price}</del></span>
               {/if}
            {/if}
         {/function}

         <div class="catalog-buy-box">
            <div class="price">
               {block "price"}
                  {sumDiscount}
                  {$product.price_array|format_price}
               {/block}
            </div>

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

               <div class="submit-block form-inline">
                  <input class="form-control orderInput disable-spinner" type="number" name="No" value="1">
                  <div class="buy_count">
                     <button type="button" class="fc fc-angle-up plus_unit"></button>
                     <button type="button" class="fc fc-angle-down minus_unit"></button>
                  </div>
                  {block "buy_btn"}
                     <button type="submit" value="{t}Koupit{/t}" class="btn btn-primary"
                             title="{t}Koupit{/t} {$product.title}">{t}Koupit{/t}</button>
                  {/block}
               </div>
            </form>
         </div>

         <div class="h4">
            <a href="{url s=product IDmodel=$product.model_old_id TITLE=$product.model_title}{$hash}">
               <i class="fc icons_arrow_right"></i> {t}další produkty{/t}</a>
         </div>

         <div class="descr">
            {if $product.parameters}
               {$product.parameters|strip_tags}
            {else}
               {$description = ""}
               {if $product.longDescr}
                  {$description = $product.longDescr|markdown2html|strip_tags|trim}
               {elseif $product.model_data.descr}
                  {$description = $product.model_data.descr|markdown2html|strip_tags|trim}
               {elseif $product.serie_data.descr}
                  {$description = $product.serie_data.descr|markdown2html|strip_tags|trim}
               {/if}

               {$descrList = preg_split("/\./", $description)} {* rozdelim popis do pole podle ". " *}

               {if $descrList|count > 1 or $descrList[0]|count_characters > 2} {* vyfiltruje prazdny popisy, kdyz zustane <p> *}
                  {$charCount = 0}

                  {foreach $descrList as $sentence}
                     {$clean_sentence = $sentence|strip_tags|trim}
                     {if $charCount + $clean_sentence|count_characters > 275}{break}{/if} {* pokud to presanhne 400 znaku, prestavam vypisovat vety *}
                     {if $clean_sentence|count_characters > 0} {* preskocim prazdne polozky v poli *}
                        {$clean_sentence nofilter}.
                        {$charCount = $charCount + $clean_sentence|count_characters}
                     {/if}
                  {/foreach}
               {/if}
            {/if}
         </div>

         {block "top10-delivery"}
            <div class="delivery">
               <p>{t}Kdy zásilku obdržím?{/t}</p>
               <p>{t}Česká Pošta{/t} <strong>{t}2-4 pracovní dny{/t}</strong></p>
            </div>
         {/block}
      </div>
   {/foreach}
</div>
