<div id="flapBalikobotSettings" class="tab-pane fade in boxFlex">
    {if $tab.data.balikobot.authorizationFailed}
       <div class="row bottom-space">
          <div class="alert alert-danger alert-dismissable">
              {$tab.data.balikobot.authorizationFailed}
          </div>
       </div>
    {/if}
   <div class="row">
      <div class="col-md-11">
         <h1 class="h4 main-panel-title">Párování se systémem Balíkobot</h1>
      </div>
      <div class="col-md-1">
         <a href="javascript:help('balikobot');"><i class="btn btn-info bi bi-question-circle"></i></a>
      </div>
   </div>
   <div class="form-group">
      <div class="col-md-12">
         Pro správné zpracování objednávek systémem balíkobot je třeba správně párovat dopravce a způsoby dopravy, viz návod.
      </div>
   </div>
   <div class="form-group">
      <div class="col-md-3 control-label">
         <label>Doprava</label>
      </div>
      <div class="col-md-2 control-label">
         <label>Přepravce</label>
      </div>
      <div class="col-md-2 col-md-offset-1 control-label">
         <label>Typ přepravy</label>
      </div>
      <div class="col-md-2 col-md-offset-1 control-label">
         <label>Zpráva uživatelům</label>
      </div>
   </div>

    {foreach $tab.data.delivery_type as $deliver}
       <div class="form-group">
          <div class="col-md-3 control-label">
             <label>{$deliver.name_admin|default:$deliver.name}</label>
          </div>
          <div class="col-md-3">
              {print_select name="data[balikobot][delivery_type][{$deliver.id}][carrier]" var=$tab.data.carriers selected=$body.data.balikobot.delivery_type[$deliver.id].carrier keep_value=true}
          </div>
          <div class="col-md-3">
              {if $body.data.balikobot.delivery_type[$deliver.id].carrier}
                  {print_select name="data[balikobot][delivery_type][{$deliver.id}][carrierService]" var=$tab.data.carrierServices[$body.data.balikobot.delivery_type[$deliver.id].carrier] selected=$body.data.balikobot.delivery_type[$deliver.id].carrierService keep_value=true}
              {else}
                 Nejprve vyberte přepravce a uložte.
              {/if}
          </div>

          <div class="col-md-3">
             <select name="data[balikobot][delivery_type][{$deliver.id}][message_name]" class="selecter">
                <option value="" {if $body.balikobot.data.delivery_type[$deliver.id].message_name == ""}selected{/if}>----</option>
                 {foreach $view->getEmail()->getOrderMessages() as $message}
                    <option value="{$message.name}"
                            {if $body.data.balikobot.delivery_type[$deliver.id].message_name == $message.name}selected{/if}>{$message.name}</option>
                 {/foreach}
             </select>
          </div>
       </div>
    {/foreach}

   <div class="row bottom-space">
      <div class="col-md-12">
         <h1 class="h4 main-panel-title">Nastavení dobírky</h1>
      </div>
   </div>

   <div class="form-group">
      <div class="col-md-5 control-label">
         <label>Nastavit k balíku dobírku, kdykoli má objednávka nedoplatek</label>
      </div>
      <div class="col-md-2">
          {print_toggle nameRaw="data[balikobot][cod_remaining]" value=$body.data.balikobot.cod_remaining attrs='id="balikobot_cod_remaining"'}
      </div>
   </div>

   <div class="row bottom-space">
      <div class="col-md-12">
         <h1 class="h4 main-panel-title">Propojení s Balíkobotem skrze API</h1>
      </div>
   </div>

   <div id="balikobot_users">
      <div class="row bottom-space">
         <div class="col-md-3">
            <a href="#" data-form-add class="btn btn-success btn-block"><span class="glyphicon glyphicon-plus"></span>&nbsp;Přidat svozové
               místo</a>
         </div>
      </div>

      <div class="panel-group panel-group-lists panel">
          {foreach array_merge([[]], $tab.data.balikobot.users) as $index => $user}
             <div class="panel" {if $index == 0}data-form-new style="display:none" {else}data-form-item{/if}>
                 {if $index > 0}
                    <input type="hidden" name="data[balikobot][users][{$index-1}][name]" value="{$user.name}">
                    <input type="hidden" name="data[balikobot][users][{$index-1}][user]" value="{$user.user}">
                    <input type="hidden" name="data[balikobot][users][{$index-1}][key]" value="{$user.key}">
                 {/if}
                <div class="panel-body">
                   <div class="form-group">
                      <div class="col-md-2 control-label">
                         <label>Název</label>
                      </div>
                      <div class="col-md-7">
                         <input type="text" class="form-control input-sm" name="{$tab.prefix}[users][{$index}][name]" size="50"
                                value="{$user.name}">
                      </div>
                      <div class="col-md-1 col-md-offset-2">
                         <a class="btn-sm btn btn-danger" data-form-delete>
                            <input class="hidden" type="checkbox" name="{$tab.prefix}[users][{$index}][delete]"/>
                            <span class="glyphicon glyphicon-remove"></span>
                         </a>
                      </div>
                   </div>
                   <div class="form-group">
                      <div class="col-md-2 control-label">
                         <label>API uživate</label>
                      </div>
                      <div class="col-md-7">
                         <input type="text" class="form-control input-sm" name="{$tab.prefix}[users][{$index}][user]" size="50"
                                value="{$user.user}">
                      </div>
                   </div>
                   <div class="form-group">
                      <div class="col-md-2 control-label">
                         <label>API klíč</label>
                      </div>
                      <div class="col-md-7">
                         <input type="text" class="form-control input-sm" name="{$tab.prefix}[users][{$index}][key]" size="50"
                                value="{$user.key}">
                      </div>
                   </div>
                </div>
             </div>
          {/foreach}
      </div>

      <script type="application/javascript">
         initForm({
            selector: '#balikobot_users'
         });
      </script>
   </div>

   <div class="form-group">
      <div class="col-md-4 control-label">
         <label for="balikobot_delivery_check">Zapnout automatické načítání stavu doručení</label>
         <a class="help-tip" data-toggle="tooltip" title="Konečné stavy doručení se budou propisovat do historie objednávky."><i
               class="bi bi-question-circle"></i></a>
      </div>
      <div class="col-md-4">
          {print_toggle nameRaw="data[balikobot][delivery_check]" value=$body.data.balikobot.delivery_check attrs='id="balikobot_delivery_check"'}
      </div>
   </div>
   <div class="form-group" id="order-status-delivered">
      <div class="col-md-4 control-label">
         <label>Změna stavu objednávky po převzetí</label>
      </div>
      <div class="col-md-4">
          {print_select name="data[order_status_delivered]" var=(['keep'=>'neměnit']+$cfg.Order.Status.global) selected=$dbcfg.order_status_delivered}
      </div>
   </div>

   <script>
      $('input[name="data[balikobot][delivery_check]"]').change(function () {
         $('#order-status-delivered').toggle($(this).is(':checked'));
      }).change();
   </script>
</div>
