{extends "ordering.tpl"}

{block "order-content" prepend}
   <div class="cart-summary-message">
      <div class="alert alert-info">
         {t}Překontrolujte si košík a odešlete objednávku.{/t}
      </div>
   </div>
{/block}

{block "order-content"}
   {$deliveryType = $body->getDeliveryType()}

   <div class="row">
      <div class="col-md-4 col-lg-4">
         <h3 class="form-title">{t}Kontaktní údaje{/t}</h3>
         <ul class="summary-list">
            <li><strong>{$body.invoice.name} {$body.invoice.surname}</strong></li>
            <li>{$body.invoice.email}</li>
            <li>{$body.invoice.phone}</li>
         </ul>
      </div>
      {if $body.invoice.street || $body.invoice.city || $body.invoice.zip}
         <div class="col-md-4 col-lg-4">
            <h3 class="form-title">{if $body.delivery.name or ($deliveryType and $deliveryType->isInPerson())}{t}Fakturační adresa{/t}{else}{t}Doručovací adresa{/t}{/if}</h3>
            <ul class="summary-list">
               <li>{$body.invoice.street}</li>
               {if $body.invoice.custom_address}
                  <li>{$body.invoice.custom_address}</li>
               {/if}
               <li>{$body.invoice.zip} {$body.invoice.city}</li>
               {if $body.invoice.state}
                  <li>{$body.invoice.state}</li>
               {/if}
               <li>{$cfg.Order.Countries[$body.invoice.country]}</li>
            </ul>
         </div>
      {/if}
      {if $body.invoice.firm || $body.invoice.ico || $body.invoice.dic}
         <div class="col-md-4 col-lg-4">
            <h3 class="form-title">{t}Firemní údaje{/t}</h3>
            <ul class="summary-list">
               <li>{$body.invoice.firm}</li>
               <li>{$body.invoice.ico}</li>
               <li>{$body.invoice.dic}</li>
            </ul>
         </div>
      {/if}
   </div>

   <hr>

   {if $deliveryType}
      <div class="row">
         <div class="col-md-4 col-lg-4">
            <h3>{t}Doprava a platba{/t}</h3>

            <ul class="summary-list">
               <li>{$deliveryType->delivery}</li>

               {$delivery = $deliveryType->getDelivery()}
               {if $delivery and $delivery.class != "BalikNaPostu"}
                  {* odpoledni doruceni *}
                  <li>{$delivery->printDeliveryInfo() nofilter}</li>
               {/if}

               {* puvodni payment-class uz neni potreba, docasne reseni pro jawu *}
               {block "payment-class-new"}
                  {$payment = $deliveryType->getPayment()}
                  {if $payment}
                     <li>{$payment->getName() nofilter}</li>
                  {else}
                     <li>{$deliveryType->payment}</li>
                  {/if}
               {/block}
            </ul>
         </div>

         {if $body.delivery.name || $body.delivery.surname || $body.delivery.street}
            <div class="col-md-4 col-lg-4">
               <h3 class="form-title">{if $delivery.class == "BalikNaPostu"}{t}Zboží doručíme na poštu{/t}{else}{t}Zboží doručíme na adresu{/t}{/if}</h3>
               <ul class="summary-list">
                  {if $delivery.class == "BalikNaPostu"}
                     <li>{$delivery->printDeliveryInfo() nofilter}</li>
                  {else}
                     <li>{$body.delivery.name} {$body.delivery.surname}</li>
                  {/if}
                  {if $body.delivery.firm}
                     <li>{$body.delivery.firm}</li>
                  {/if}
                  <li>{$body.delivery.street}</li>
                  {if $body.delivery.custom_address}
                     <li>{$body.delivery.custom_address}</li>
                  {/if}
                  <li>{$body.delivery.zip} {$body.delivery.city}</li>
                  {if $body.delivery.state}
                     <li>{$body.invoice.state}</li>
                  {/if}
                  <li>{$cfg.Order.Countries[$body.delivery.country]}</li>
                  {if $body.delivery.phone}
                     <li>{$body.delivery.phone}</li>
                  {/if}
               </ul>
            </div>
         {/if}
      </div>

      <hr>
   {/if}


   {if $body.note}
      <h2>{t}Poznámka k objednávce{/t}</h2>
      <p>{$body.note|escape:'htmlall'|nl2br nofilter}</p>
      <hr>
   {/if}

   {if $body.register}
      <p>{t ucet=$body.invoice.email escape=false}K objednávce Vám vytvoříme nový uživatelský účet <strong>{ucet}</strong>{/t}</p>
      <hr>
   {/if}

   {if $body.products}
      {block "order-summary-products"}
         <h3>{t}Zboží{/t}</h3>

         <div class="table-cart summary">
            {foreach $body.products as $product}

               <div class="product">
                  <div class="product-inner display-table" data-cart="row">
                     <div class="col-xs-1 product-image">
                        <a href="{url s=product IDproduct=$product.id TITLE=$product.title}" title="{t}Zobrazit zboží{/t}">
                           {block "order-summary-img"}
                              <img src="{get_photo photo=$product.image size=2}" alt="{$product.title}" class="img-responsive">
                           {/block}
                        </a>
                     </div>
                     {block "order-summary-title"}
                        <div class="col-xs-3 product-title">
                           <a href="{url s=product IDproduct=$product.id TITLE=$product.title}"
                              title="{t}Zobrazit zboží{/t}">{$product.title}</a>
                        </div>
                     {/block}
                     {block "order-summary-avaiability"}
                        <div class="col-xs-2 product-availability">
                           {if $product.availability eq 0 and $product.inStore eq 0}
                              <p class="delivery delivery-notinstore">{t}nedostupné{/t}</p>
                           {elseif $product.availability eq 0 and $product.inStore gt 0 }
                              <p class="delivery delivery-partly">{t pocet=$product.inStore}skladem pouze {pocet} ks{/t}</p>
                           {elseif $product.availability eq 1}
                              <p class="delivery delivery-instore">{t}skladem{/t}</p>
                           {elseif $product.availability eq 2}
                              <p class="delivery delivery-instore">{t}skladem u dodavatele{/t}</p>
                           {/if}
                        </div>
                     {/block}
                     {block "order-summary-pieces"}
                        <div class="col-xs-2  product-pieces">
                           {$pieces_precision = $product.product.unit.pieces_precision|default:0}
                           {$product.pieces|number_format:$pieces_precision}
                           {if $module.PRODUCTS__UNITS}
                              {$product.product.unit.short_name|lower}
                           {else}
                              {t}Ks{/t}
                           {/if}
                        </div>
                     {/block}
                     {block "order-summary-item-price"}
                        <div class="col-xs-2 product-price-total">
                           {$product.totalPrice.value_with_vat|format_price}
                        </div>
                     {/block}
                  </div>
               </div>
               {block "product-sets"}
                  {if $product.sets}
                     {foreach $product.sets as $set_product}
                        {$set_product->fetchImages(2)}
                        <div class="row product set" data-cart="row">
                           <div class="product-image">
                              <a title="{t}Zobrazit zboží{/t}" href="{url s=product IDproduct=$set_product.id TITLE=$set_product.title}">
                                 <img src="{get_photo photo=$set_product.image size=2}" alt="">
                              </a>
                           </div>
                           <div class="product-title">
                              <a href="{url s=product IDproduct=$set_product.id TITLE=$set_product.title}"
                                 title="{t}Zobrazit zboží{/t}">{$set_product.title}</a>
                              <span>{t}set{/t}</span>
                           </div>
                           <div class="product-variations">
                              {$variations = $set_product->fetchVariations(true)}
                              {$id_selected = $product.note.set_variation[$set_product.id]}
                              {$variation = $variations.variations[$id_selected]}

                              {foreach $variation.combinations as $index => $comb}
                                 {$label = $variations.labels[$comb.id_label]}
                                 {$label.label}: {$label.values[$comb.id_value]}
                                 {if !$comb@last}, {/if}
                              {/foreach}
                           </div>
                        </div>
                     {/foreach}
                  {/if}
               {/block}
            {/foreach}

            {ifmodule ORDER_DISCOUNT}
               {$gifts = $body->getPurchaseState()->getCustomData('gift')}

               {$selected_products = []}
               {foreach $gifts as $discountId => $selectedGifts}
                   {$tmp_selected = array_filter(array_column($selectedGifts, 'id_product'))}
                   {if $tmp_selected}
                       {$selected_products = array_merge($selected_products, $tmp_selected)}
                   {/if}
               {/foreach}

               {if $selected_products}
                  {foreach $body->getPurchaseState()->getDiscountHandlers() as $handler}
                     {$data = $handler->getData()}
                     {* Pokud jsou varianty, `id_product` je id produktu a `gift` je id varianty.
                        Bez variant je jen `gift` = id produktu. *}
                     {$gift = $data['id_product']|default:$data['gift']}
                     {if $gift and in_array($gift, $selected_products)}
                        {$vars = $handler->getVars()}
                        {$product = $vars['products'][$gift]}

                        {if $product}
                           {$product->fetchImages(2)}
                           <div class="product">
                              <div class="product-inner display-table" data-cart="row">
                                 <div class="col-xs-1 product-image">
                                    <a href="{url s=product IDproduct=$product.id TITLE=$product.title}" title="{t}Zobrazit produkt{/t}">
                                       <img src="{get_photo photo=$product.image size=2}" alt="{$product.title}"
                                            class="img-responsive">
                                    </a>
                                 </div>
                                 <div class="col-xs-3 product-title">
                                    <a href="{url s=product IDproduct=$product.id TITLE=$product.title}"
                                       title="{t}Zobrazit produkt{/t}">{$product.title}</a><br>
                                    <span class="variation">
                                       {if $vars.price->getPriceWithVat()->isZero()}
                                          {t}Dárek zdarma{/t}
                                       {else}
                                          {$vars.title|default:"{t}Dárek zdarma{/t}"}
                                       {/if}
                                    </span>
                                 </div>
                                 <div class="col-xs-2 product-availability">
                                 </div>
                                 <div class="col-xs-2  product-pieces">
                                 </div>
                                 <div class="col-xs-2 gift-price-total product-price-total">
                                    {if $vars.price && $vars.price->getPriceWithVat()->isZero()}{t}zdarma{/t}{else}{$vars.price|format_price}{/if}
                                 </div>
                              </div>
                           </div>
                        {/if}
                     {/if}
                  {/foreach}
               {/if}
            {/ifmodule}
         </div>

         <div class="clearfix"></div>
      {/block}
   {else}
      <div class="alert alert-info" role="alert">
         {t}Žádný produkt{/t}
      </div>
   {/if}

   {* box s cenou, zobrazuje dopravu *}
   {block 'order-summary-price-box'}
      <div class="row">
         <div class="col-md-6 col-xs-12 pull-right">
            {showPriceBox transport=1}
         </div>
      </div>
   {/block}

   {block 'cart-buttons'}
      {cartBtns submitName='SubmitOrder' valueNext="{t price=$body.totalPricePay|format_price}Koupit za {price}{/t}"}
   {/block}
{/block}
