{extends "frame.tpl"}

{block css append}
   <style>
      h1 { font-size:20rem; margin:0 5rem 0 5rem; }
      h1.small { font-size:5rem; margin:2rem; }
      dl {
         padding: 0.5em;
         padding-top: 0;
         margin-top: 0;
         font-size: 1.5rem;
      }
      dt {
         float: left;
         clear: left;
         width: 12rem;
         text-align: right;
      }
      dt::after {
         content: ":";
      }
      dd {
         margin: 0 0 0 13rem;
         padding: 0 0 0.5rem 0;
         font-weight: bold;
      }
      dd a, dd small { font-weight:initial; }
   </style>
{/block}

{block "content"}
   <div class="container">
      <div class="row">
         <div class="col-md-12">
            <div class="panel panel-default first">
               <div class="panel-body">
                  {if $variation}
                     {if mb_strlen($variation.note) <= 4}
                        <h1 title="Pozice na skladě">{$variation.note}</h1>
                     {else}
                        <h1 title="Pozice na skladě" class="small">{$variation.note}</h1>
                     {/if}
                  {else}
                     {if mb_strlen($product.note) <= 4}
                        <h1 title="Pozice na skladě">{$product.note}</h1>
                     {else}
                        <h1 title="Pozice na skladě" class="small">{$product.note}</h1>
                     {/if}
                  {/if}
                  <dl>
                     <dt>Kód</dt>
                     <dd>{if $variation.code}{$variation.code}{elseif $product.code}{$product.code}{else} - {/if}</dd>
                     {if $variation}
                        <dt>Kusů na skladě</dt>
                        <dd>{$variation.in_store}</dd>
                     {/if}
                     <dt>Kusů na skladě</dt>
                     <dd>{$product.in_store} &nbsp;<small>(všechny varianty)</small></dd>
                     {if $variation}
                        <dt>Název varianty</dt>
                        <dd>{$variation.title}</dd>
                     {/if}
                     <dt>Produkt</dt>
                     <dd><a href="launch.php?s=products.php&acn=edit&ID={$product.id}" title="Upravit produkt">{$product.title}</a></dd>
                     <dt>EAN</dt>
                     <dd>{if $variation}{$variation.ean}{else}{$product.ean}{/if}</dd>
                  </dl>

                  <div class="row">
                     <div class="col-md-4">
                        <button data-print-label type="button" class="btn btn-primary btn-block">
                           <span class="glyphicon glyphicon-print"></span>
                           Tisk štítku
                        </button>
                     </div>
                  </div>
               </div>
            </div>

            <div class="panel panel-default">
               <div class="panel-body">
                  <div class="row">
                     <div class="col-xs-12">
                        <input type="text" data-autocomplete-search="product" autocomplete="off" class="form-control input-sm autocomplete-control" placeholder="Vyhledat produkt">
                     </div>
                  </div>
               </div>
            </div>

            <script type="text/javascript" src="/{trim($cfg['Path']['admin'], '/')}/static/js/qwebchannel.js?v4"></script>
            <script type="application/javascript">
               function printLabel(url) {
                  console.log('print');

                  var loc = window.location,
                     fullUrl = loc.href.substring(0, loc.href.lastIndexOf('/')) + '/launch.php' + url;

                  if (!window.kupshopCheckout) {
                     window.connectWebChannel(function (channel) {
                        channel.objects.kupshopCheckout.print(fullUrl);
                     });
                  } else {
                     kupshopCheckout.print(fullUrl);
                  }
               }

               $('[data-print-label]').click(function () {
                  printLabel('{$print_url nofilter}');
               });

               $('[data-autocomplete-search="product"]')
                  .adminVariationAutoComplete({
                     select: function(e, item) {
                        var url = 'launch.php?s=productInfo.php&';

                        if (item.variation) {
                           url += 'variationID='+item.variation;
                        } else if (item.product.from_variation > 0) {
                           url += 'variationID=' + item.product.value_variation;
                        } else if (item.product.variations) {
                           url += 'variationID=' + item.product.value_variation;
                        } else {
                           url += 'ID='+item.product.value;
                        }

                        window.location.assign(url);
                     }
                  });
            </script>

         </div>
      </div>
   </div>
{/block}
