{extends "../window.tpl"}

{block tabs}
   {windowTab id='flapPayment'}
   {windowTab id='flapPaymentDescription'}
{/block}

{block tabsContent}
   <div id="flapPayment" class="tab-pane fade active in boxStatic">
   <h1 class="h4 main-panel-title">{'flapPayment'|translate}</h1>
   <div class="form-group">
      <div class="col-md-2 control-label"><label>{'name'|translate}</label></div>
      <div class="col-md-4">
         <input type="text" class="form-control input-sm" name="data[name]" size="50" maxlength="50" value="{$body.data.name}">
      </div>
      <div class="col-md-2 control-label"><label>{'name_admin'|translate}</label></div>
      <div class="col-md-4">
         <input type="text" class="form-control input-sm" name="data[name_admin]" size="100" maxlength="100" value="{$body.data.name_admin}">
      </div>
   </div>
   <div class="form-group">
      <div class="col-md-2 control-label"><label>{'flapPhoto'|translate:'photos'}</label></div>
      <div class="col-md-10">
         <div class="row">
            <div class="col-md-4">
               <img src="{static_url url=$body.data.photo_array.src}" alt="{$body.data.photo_array.descr}" style="max-width: 120px;height: auto;">
               {if !$body.data.photo}
                  <a class="help-tip" data-toggle="tooltip" title="" data-original-title="Výchozí obrázek platby" style="position: relative;">
                     <i class="bi bi-question-circle"></i>
                  </a>
               {/if}
            </div>
            <div class="col-md-8">
               {if $body.data.photo}
                  <a href="{$ctrl.currUrl.Rel}&amp;acn=erasephoto" class="btn btn-danger">
                     {'deletePhoto'|translate:'producers'}
                  </a>
                  <a href="javascript:nw('imageEditor', '{$body.data.id}', 'type=payment');" class="btn"><span class="glyphicon glyphicon-cog m-r-1"></span> Upravit</a>
               {else}
                  <input type="file" class="filestyle" name="photo" data-iconName="glyphicon-folder-open" data-buttonText="{'sectionNewPhoto'|translate:'photos'}">
               {/if}
            </div>
         </div>
      </div>

      <div class="col-md-4">
          {if $body.data.class}
             {if $body.data.base_icon}
                Výchozí obrázek:
                <img src="{static_url url=$body.data.base_icon.src}" alt="{$body.data.base_icon.descr}" style="max-width: 120px;height: auto;">
             {/if}
          {else}

          {/if}
      </div>
   </div>
   <div class="form-group">
      <div class="col-md-2 control-label"><label>{'price'|translate:'base'}</label></div>
      <div class="col-md-3">

         <div class="input-group">

            {if $body.data.currencies|count > 1}
               <div class="input-group-btn" style="min-width:70px;">
                  <select class="selecter" name="data[currency]">
                     {foreach $body.data.currencies as $currencyID => $currency}
                        <option{if $currencyID == $body.data.currency} selected{/if}>{$currencyID}</option>
                     {/foreach}
                  </select>
               </div>
            {/if}

            <input type="text" class="form-control input-sm" name="data[price]" id="price" maxlength="20" value="{$body.data.price|round:2}" onKeyPress="checkInputData('float');"/>
            <div class="input-group-btn" id="priceWithVatDropdown">
               <a class="btn btn-primary dropdown-toggle btn-sm" data-toggle="dropdown"> <span id="priceWithVatState">{if $body.data.priceWithVat}s{else}bez{/if} DPH</span> <span
                     class="caret"></span></a>
               <ul class="dropdown-menu">
                  <li><a data-value="1">{'withTax'|translate:'choice'}</a></li>
                  <li><a data-value="0">{'withoutTax'|translate:'choice'}</a></li>
               </ul>
            </div>
         </div>
      </div>
      <input type="hidden" name="data[priceWithVat]" id="priceWithVat" value="{if $body.data.priceWithVat}1{else}0{/if}"/>
      <script type="text/javascript">
         $("#priceWithVatDropdown").on("click", "li a", function (e) {
            $("#priceWithVatState").html($(this).html());
            var value = $(this).data("value"), oldValue = $("#priceWithVat").val();
            $("#priceWithVat").val(value);
            if (oldValue != value) {
               {$adminVat = getAdminVat()}
               var vat = {$adminVat['value']},//$("#priceVat :selected").data("vat"),
                  $price = $("#price");
               switch (value) {
                  case 1:
                     $price.val(formatPrice($price.val() * (100 + vat) / 100, 2));
                     break;
                  case 0:
                     $price.val(formatPrice($price.val() * 100 / (100 + vat)));
                     break;
               }
               $('input[name=data\\[discount\\]]').keyup();
            }
         });
      </script>

      {if findModule(Modules::PRODUCTS, Modules::SUB_PRICE_BUY)}
      <div class="col-md-2 control-label"><label>{'priceBuy'|translate}</label></div>
      <div class="col-md-3">
         {include 'utils/priceDropdown.tpl' fieldName="data[price_buy]"
                  price=$body.data.price_buy currency=$body.data.currency vat=$adminVat['value']}
      </div>
      {/if}
      {block 'block-prices'}
      {/block}
   </div>
   {if {find_module name="payments"}}
      <h1 class="h4 main-panel-title">{'sectionPayment'|translate:'deliverytypes'}</h1>
      <p>{'paymentNote'|translate:'deliverytypes'}</p>
      {foreach from=$body.payments item=payment key=class name=pay}
         <div class="row">
            <div class="col-md-3">
               <div class="radio">
                  <input type="radio" class="check" name="data[class]" value="{$class}" id="link{$smarty.foreach.pay.index}" {if $body.data.class == $class}checked{/if}/>
                  <label for="link{$smarty.foreach.pay.index}">{$payment}</label>
               </div>
            </div>
         </div>
      {/foreach}
   {/if}
      </div>


      <div id="flapPaymentDescription" class="tab-pane fade in boxStatic">
         <div class="form-group">
            <div class="col-md-2 control-label">
               <label>{'description'|translate}</label> <a class="help-tip" data-toggle="tooltip" title="{'descriptionHelp'|translate}"><i class="bi bi-question-circle"></i></a>
            </div>
            <div class="col-md-10">
               <textarea name="data[description]" class="form-control input-sm">{$body.data.description}</textarea>
               {insert_wysiwyg target="data[description]"}
               <span class="help-block">
            {'infoPlaceholder1'|translate:'deliverytypes'} <a href="javascript:nw('emails', '0', '&flap=2&symbols=1')">{'infoPlaceholder2'|translate:'deliverytypes'}</a>
         </span>
            </div>
         </div>
         <div class="form-group">
            <div class="col-md-2 control-label">
               <label>{'cart_description'|translate}</label>
               <a class="help-tip" data-toggle="tooltip" title="{'cart_descriptionHelp'|translate}">
                  <i class="bi bi-question-circle"></i>
               </a>
            </div>
            <div class="col-md-10">
               <textarea name="data[cart_description]" class="form-control input-sm">{$body.data.cart_description}</textarea>
               {insert_wysiwyg target="data[cart_description]"}
            </div>
         </div>
      </div>
{/block}

<script type="text/javascript">
   {block onready append}
   $('#priceWithVatDropdown li a[data-value="1"]').trigger('click');
   {/block}
</script>
