<div id="flapDeliveryPayment" class="tab-pane fade in boxFlex">

   {function renderInputs}
      {foreach $inputs as $name => $config}
         <div class="form-group form-group-flex">
            <div class="col-md-2 control-label">
               <label>{$config.title}</label>
               {if $config.tooltip }
                  <a class="help-tip" data-toggle="tooltip" title="{$config.tooltip}"><i class="bi bi-question-circle"></i></a>
               {/if}
            </div>
            {$inputName = "data[{$type}][{$key}][{$name}]"}
            {if $config.type == 'toggle'}
               <div class="col-md-4">
                  <input type="hidden" name="{$inputName}" value=""/>
                  <label class="toggle">
                     <input name="{$inputName}" type="checkbox" value="1" {if $data[$key][$name]}checked{/if} />
                     <span class="handle"></span>
                  </label>
               </div>
            {elseif $config.type == 'select'}
               <div class="col-md-4">
                  <select class="selecter" name="{$inputName}">
                     <option value="">-- nevybráno --</option>
                     {foreach $config.options as $id => $option}
                        <option value="{$id}" {if $id == $data[$key][$name] && $data[$key][$name] != ''}selected{/if}>{$option}</option>
                     {/foreach}
                  </select>
               </div>
            {elseif $config.type == 'textarea'}
               <div class="col-md-7">
                  <textarea class="form-control input-sm" name="{$inputName}">{$data[$key][$name]}</textarea>
               </div>
            {elseif $config.type == 'hidden'}
               <input type="hidden" name="{$inputName}" value="{$data[$key][$name]}"/>
            {elseif $config.type == 'label'}
               <div class="col-md-4">
                  {$config.value nofilter}
               </div>
            {elseif !empty($config.type)}
               <div class="col-md-4">
                  <input type="{$config.type}" class="form-control input-sm" name="{$inputName}" placeholder="{$config.placeholder}"
                         value="{$data[$key][$name]}"
                         {if $config.type == 'password'}autocomplete="new-password"{/if}
                  >
               </div>
            {elseif !empty($config.text)}
               <div class="col-md-7">
                   {$config.text}
               </div>
            {/if}
            {if $config.button}
               <div class="col-md-2">
                  <button type="submit" class="btn {if $config.buttonClass}{$config.buttonClass}{else}btn-success{/if} btn-block" name="acn" value="{$config.buttonValue}">{$config.button}</button>
               </div>
            {/if}
         </div>
      {/foreach}

   {/function}

   <h4 class="main-panel-title">Dopravy</h4>

   <div class="form-group">
      <div class="col-md-4 control-label">
         <label>{'vatsFromProducts'|translate:'delivery'}</label>
      </div>
      <div class="col-md-1">
         {print_toggle name="delivery_config][from_products" value=$body.data.delivery_config.from_products|default:$dbcfg.delivery_config.from_products|default:'N'}
      </div>
   </div>
   <div class="form-group">
      <div class="col-md-4 control-label">
         <label>{'vatsFromTop'|translate:'delivery'}</label>
         <a class="help-tip" data-toggle="tooltip" title="{'vatsFromTopTooltip'|translate:'delivery'}"><i
                    class="bi bi-question-circle"></i></a>

      </div>
      <div class="col-md-1">
         {print_toggle name="delivery_config][vats_from_top" value=$body.data.delivery_config.vats_from_top|default:$dbcfg.delivery_config.vats_from_top|default:'N'}
      </div>
   </div>
   <div class="form-group">
      <div class="col-md-4 control-label">
         <label>{'holidaysByCountry'|translate:'deliveryPaymentTab'}</label>
         <a class="help-tip" data-toggle="tooltip" title="{'holidaysByCountryInfo'|translate:'deliveryPaymentTab'}">
            <i class="bi bi-question-circle"></i>
         </a>
      </div>
      <div class="col-md-3">
         <select class="selecter" name="data[delivery_config][holidaysByCountry]">
            <option value="dispatch" {$body.data.delivery_config.holidaysByCountry|selected:"dispatch"}>{'countryDispatch'|translate:'deliveryPaymentTab'}</option>
            <option value="delivery" {$body.data.delivery_config.holidaysByCountry|selected:"delivery"}>{'countryDelivery'|translate:'deliveryPaymentTab'}</option>
            <option value="dispatchDelivery" {$body.data.delivery_config.holidaysByCountry|selected:"dispatchDelivery"}>{'countryDispatchDelivery'|translate:'deliveryPaymentTab'}</option>
         </select>
      </div>
   </div>


   {foreach $tab.data.deliveries as $key => $delivery}
      <div class="panel panel-default">
         <div class="panel-heading" data-toggle="collapse" data-target="#delivery_{$key}">
            <p style="margin-left: 10px;"><strong>{$delivery.title}</strong></p>
         </div>
         <div id="delivery_{$key}" class="panel-collapse collapse in">
            <div class="panel-body">
               {renderInputs type='deliveries' inputs=$delivery.inputs key=$key data=$body.data.deliveries}
            </div>
         </div>
      </div>
   {/foreach}

   <h4 class="main-panel-title">Platební brány</h4>

      <div class="form-group">
         <div class="col-md-4 control-label">
            <label>Změna stavu objednávky před zaplacením</label>
         </div>
         <div class="col-md-2">
            {print_select name="data[payment_config][order_status_new]" var=$cfg.Order.Status.global
               selected=$body.data.payment_config.order_status_new|default:$dbcfg.payment_config.order_status_new}
         </div>
      </div>
      <div class="form-group">
         <div class="col-md-4 control-label">
            <label>Změna stavu objednávky po zaplacení</label>
         </div>
         <div class="col-md-2">
            {print_select name="data[payment_config][order_status_finished]" var=(['keep'=>'neměnit']+$cfg.Order.Status.global)
               selected=$body.data.payment_config.order_status_finished|default:$dbcfg.payment_config.order_status_finished}
         </div>
      </div>
      <div class="form-group">
         <div class="col-md-4 control-label">
            <label>Po zaplacení objednávky automaticky nastavit datum vyřízení (DUZP)</label>
         </div>
         <div class="col-md-2">
            {print_toggle name="payment_config][order_paid_date_handle"
               value=$body.data.payment_config.order_paid_date_handle|default:$dbcfg.payment_config.order_paid_date_handle|default:'N'}
         </div>
      </div>
      <div class="form-group">
         <div class="col-md-4 control-label">
            <label>Při vrácení platby automaticky vrátit přes platební bránu</label>
         </div>
         <div class="col-md-2">
            {print_toggle name="payment_config][return_payment_auto_gate"
               value=$body.data.payment_config.return_payment_auto_gate|default:$dbcfg.payment_config.return_payment_auto_gate|default:'Y'}
         </div>
      </div>

   {foreach $tab.data.payments as $key => $payment}
      <div class="panel panel-default">
         <div class="panel-heading" data-toggle="collapse" data-target="#payment_{$key}">
            <p style="margin-left: 10px;"><strong>{$payment.title}</strong></p>
         </div>
         <div id="payment_{$key}" class="panel-collapse collapse in">
            <div class="panel-body">
               {renderInputs type='payments' inputs=$payment.inputs key=$key data=$body.data.payments}
            </div>
         </div>
      </div>
      {foreachelse}
      <div class="infobox">
         <p>Nejsou aktivní žádné platební brány, ke kterým by bylo možné přidávat nastavení.</p>
      </div>
   {/foreach}

   <h4 class="main-panel-title">Platby převodem</h4>
   <div class="panel panel-default">
      <div class="panel-heading" data-toggle="collapse" data-target="#show_qr_payment">
         <p style="margin-left: 10px;"><strong>{'paymentInstruction'|translate:'deliveryPaymentTab'}</strong></p>
      </div>
      <div id="#show_qr_payment" class="panel-collapse collapse in">
         <div class="panel-body">
            <div class="form-group form-group-flex">
               <div class="col-md-2 control-label">
                  <label>{'showPaymentInstruction'|translate:'deliveryPaymentTab'}</label>
               </div>
               <div class="col-md-1">
                   {print_toggle name="payment_config][show_payment_instruction" value=$body.data.payment_config.show_payment_instruction|default:0 numeric=true }
               </div>
            </div>
         </div>
      </div>
   </div>

    {if $tab.data.autopayments}
      {foreach $tab.data.autopayments as $key => $payment}
         <div class="panel panel-default">
            <div class="panel-heading" data-toggle="collapse" data-target="#payment_{$key}">
               <p style="margin-left: 10px;"><strong>{$payment.title}</strong></p>
            </div>
            <div id="payment_{$key}" class="panel-collapse collapse in">
               <div class="panel-body">
                  {renderInputs type='payments' inputs=$payment.inputs key=$key data=$body.data.payments}
               </div>
            </div>
         </div>
      {/foreach}
   {/if}
</div>
