<div id="flapFlexiBeeSettings" class="tab-pane fade in boxFlex">
   <div class="row bottom-space">
      <div class="col-md-12">
         <h1 class="h4 main-panel-title">Nastavení API</h1>
      </div>
   </div>

   <input type="hidden" name="disable_autoload[flexibee]" value="1">

   <div class="form-group">
      <div class="col-md-2 control-label">
         <label>Adresa FlexiBee</label>
      </div>
      <div class="col-md-5">
         <input type="text" class="form-control input-sm" name="data[flexibee][api][url]"
                value="{$body.data.flexibee.api.url}">
      </div>
      <div class="col-md-3 col-md-offset-1">
         <button type="submit" class="btn btn-success btn-block" name="acn" value="checkConnection">Ověřit připojení</button>
      </div>
   </div>
   <div class="form-group">
      <div class="col-md-2 control-label">
         <label>Firma</label>
      </div>
      <div class="col-md-5">
         <input type="text" class="form-control input-sm" name="data[flexibee][api][company]"
                value="{$body.data.flexibee.api.company}">
      </div>
       {if $tab.data.changesApiButton}
         <div class="col-md-3 col-md-offset-1">
            <button type="submit" class="btn btn-success btn-block" name="acn" value="changesAPIEnable">Zapnout ChangesAPI</button>
         </div>
       {/if}
   </div>
   <div class="form-group">
      <div class="col-md-2 control-label two-lines">
         <label>Uživatelské jméno</label>
      </div>
      <div class="col-md-2">
         <div class="input-group">
            <input type="text" class="form-control input-sm" name="data[flexibee][api][user]"
                   value="{$body.data.flexibee.api.user}">
         </div>
      </div>
      <div class="col-md-1 control-label">
         <label>Heslo</label>
      </div>
      <div class="col-md-2">
         <div class="input-group">
            <input type="password" class="form-control input-sm" name="data[flexibee][api][password]" autocomplete="new-password"
                   value="{$body.data.flexibee.api.password}">
         </div>
      </div>
   </div>

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

   <div class="panel panel-default">
      <div class="panel-heading" data-toggle="collapse" data-target="#flexibee_sync">
         <p style="margin-left: 10px;"><strong>Obecné</strong></p>
      </div>
      <div id="flexibee_sync" class="panel-collapse collapse in">
         <div class="panel-body">
            <div class="form-group">
               <div class="col-md-2 control-label">
                  <label>Povolené synchronizace</label>
               </div>
               <div class="col-md-5">
                  <select class="selecter" multiple name="data[flexibee][config][enabled_types][]">
                      {foreach $tab.data.flexibeeData.synchronizers as $type => $name}
                         <option value="{$type}"
                                 {if $body.data.flexibee.config.enabled_types && in_array($type, $body.data.flexibee.config.enabled_types)}selected{/if}>{$name}</option>
                      {/foreach}
                  </select>
               </div>
            </div>
         </div>
      </div>
   </div>

   <div class="panel panel-default">
      <div class="panel-heading" data-toggle="collapse" data-target="#flexibee_sync_stores">
         <p style="margin-left: 10px;"><strong>Sklady</strong></p>
      </div>
      <div id="flexibee_sync_stores" class="panel-collapse collapse in">
         <div class="panel-body">
            <div class="form-group">
               <div class="col-md-2 control-label">
                  <label>Synchronizované sklady</label>
               </div>
               <div class="col-md-5">
                  <select class="selecter" multiple name="data[flexibee][config][stores][]">
                      {foreach $tab.data.flexibeeData.stores as $storeId => $store}
                         <option value="{$storeId}"
                                 {if $body.data.flexibee.config.stores && in_array($storeId, $body.data.flexibee.config.stores)}selected{/if}>{$store}</option>
                      {/foreach}
                  </select>
               </div>
               <div class="col-md-3 col-md-offset-1">
                  <button type="submit" class="btn btn-success btn-block" name="acn" value="synchronizeStores">
                     Sesynchronizovat sklady
                  </button>
               </div>
            </div>
         </div>
      </div>
   </div>

   <div class="panel panel-default">
      <div class="panel-heading" data-toggle="collapse" data-target="#flexibee_sync_orders">
         <p style="margin-left: 10px;"><strong>Objednávky</strong></p>
      </div>
      <div id="flexibee_sync_orders" class="panel-collapse collapse in">
         <div class="panel-body">
            <div class="form-group">
               <div class="col-md-2 control-label">
                  <label>Středisko pro zápis</label>
               </div>
               <div class="col-md-5">
                  <select class="selecter" name="data[flexibee][config][order][central]">
                     <option value="">-- nevybráno --</option>
                      {foreach $tab.data.flexibeeData.centrals as $centralId => $name}
                         <option value="{$centralId}"
                                 {if $body.data.flexibee.config.order.central == $centralId}selected{/if}>{$name}</option>
                      {/foreach}
                  </select>
               </div>
            </div>

            <div class="form-group">
               <div class="col-md-2 control-label">
                  <label>Výchozí uživatel</label>
               </div>
               <div class="col-md-5">
                  <input class="input-sm form-control" name="data[flexibee][config][order][id_user]"
                                   value="{$body.data.flexibee.config.order.id_user}" placeholder="ID uživatele ve FlexiBee">
               </div>
            </div>

            <div class="form-group">
               <div class="col-md-2 control-label">
                  <label>Chybový stav</label>
                  <a class="help-tip" data-toggle="tooltip"
                     title="" data-original-title="Objednávky, u kterých dojde k 10 neuspěšným pokusům o synchronizaci,
                     budou přepnuty do tohoto stavu">
                     <i class="bi bi-question-circle"></i>
                  </a>
               </div>
               <div class="col-md-5">
                  <select class="selecter" name="data[flexibee][config][order][error_status]">
                     <option value="">-- neměnit stav --</option>
                     {foreach getOrderStatuses() as $key => $orderStatus}
                        <option value="{$key}"
                                {if $body.data.flexibee.config.order.error_status == $key}selected{/if}>{$orderStatus.name}</option>
                     {/foreach}
                  </select>
               </div>
            </div>

            <div class="form-group">
               <div class="col-md-2 control-label">
                  <label>
                     Obousměrná synchronizace
                     <a class="help-tip" data-toggle="tooltip"
                        title="" data-original-title="Zapnutím oboustranné synchronizace se začnou synchronizovat změny objednávek směrem
                        z FlexiBee do e-shopu. Tzn. že pokud například přidáte k objednávce ve FlexiBee novou položku, tak se položka
                        přenese i do objednávky na e-shopu. ">
                        <i class="bi bi-question-circle"></i>
                     </a>
                  </label>
               </div>
               <div class="col-md-5">
                  {print_toggle nameRaw='data[flexibee][config][order][duplex_sync]' value= $body.data.flexibee.config.order.duplex_sync}
               </div>
            </div>

            <div class="row">
               <div class="col-md-12" style="border-bottom: 1px solid #e6e9ed; margin: 5px 0 10px; padding-bottom: 6px;">
                  <strong>Změny stavů</strong>
               </div>
            </div>

            {foreach $tab.data.flexibeeData.statuses as $status}
               <div class="form-group">
                  <div class="col-md-2 control-label">
                     <label>{$status}</label>
                  </div>
                  <div class="col-md-2">
                     <select class="selecter" name="data[flexibee][config][order][statuses][{$status}][status]">
                        <option value="">-- neměnit stav --</option>
                        {foreach getOrderStatuses() as $key => $orderStatus}
                            <option value="{$key}" {if $body.data.flexibee.config.order.statuses[$status].status !== '' && $body.data.flexibee.config.order.statuses[$status].status !== null && $body.data.flexibee.config.order.statuses[$status].status == $key}selected{/if}>{$orderStatus.name}</option>
                        {/foreach}
                     </select>
                  </div>
                  <div class="col-md-3">
                     <select class="selecter" name="data[flexibee][config][order][statuses][{$status}][order_message]">
                        <option value="">-- neodesílat zprávu uživateli --</option>
                        {foreach $tab.data.orderMessages as $orderMessage}
                            <option value="{$orderMessage.id}" {if $body.data.flexibee.config.order.statuses[$status].order_message == $orderMessage.id}selected{/if}>
                                {$orderMessage.name}
                            </option>
                        {/foreach}
                     </select>
                  </div>
               </div>
            {/foreach}
         </div>
      </div>
   </div>

   <div class="panel panel-default">
      <div class="panel-heading" data-toggle="collapse" data-target="#flexibee_sync_delivery_payment">
         <p style="margin-left: 10px;"><strong>Dopravy a platby</strong></p>
      </div>
      <div id="flexibee_sync_delivery_payment" class="panel-collapse collapse in">
         <div class="panel-body">
            <div class="row">
               <div class="col-md-6">
                  <div class="row">
                     <div class="col-md-12" style="border-bottom: 1px solid #e6e9ed; margin: 5px 0 10px; padding-bottom: 6px;">
                        <strong>Dopravy</strong>
                     </div>
                  </div>
                   {foreach $tab.data.deliveries as $delivery}
                      <div class="form-group">
                         <div class="col-md-4 control-label">
                            <label>{$delivery.name}</label>
                         </div>
                         <div class="col-md-6">
                            <input class="input-sm form-control" name="data[flexibee][config][delivery][{$delivery.id}]"
                                   value="{$body.data.flexibee.config.delivery[$delivery.id]}" placeholder="Kód ve FlexiBee">
                         </div>
                      </div>
                   {/foreach}
               </div>
               <div class="col-md-6">
                   <div class="row">
                     <div class="col-md-12" style="border-bottom: 1px solid #e6e9ed; margin: 5px 0 10px; padding-bottom: 6px;">
                        <strong>Platby</strong>
                     </div>
                  </div>
                   {foreach $tab.data.payments as $payment}
                      <div class="form-group">
                         <div class="col-md-4 control-label">
                            <label>{$payment.name}</label>
                         </div>
                         <div class="col-md-6">
                            <input class="input-sm form-control" name="data[flexibee][config][payment][{$payment.id}]"
                                   value="{$body.data.flexibee.config.payment[$payment.id]}" placeholder="Kód ve FlexiBee">
                         </div>
                      </div>
                   {/foreach}
               </div>
            </div>
         </div>
      </div>
   </div>
   <div class="panel panel-default">
      <div class="panel-heading" data-toggle="collapse" data-target="#flexibee_sync_pricelists">
         <p style="margin-left: 10px;"><strong>Ceníky</strong></p>
      </div>
      <div id="flexibee_sync_pricelists" class="panel-collapse collapse in">
         <div class="panel-body">
            <div class="form-group">
               <div class="col-md-2 control-label">
                  <label>Synchronizované ceníky</label>
               </div>
               <div class="col-md-5">
                  <select class="selecter" multiple name="data[flexibee][config][pricelists][]">
                      {foreach $tab.data.flexibeeData.pricelists as $pricelistId => $pricelist}
                         <option value="{$pricelistId}"
                                 {if $body.data.flexibee.config.pricelists && in_array($pricelistId, $body.data.flexibee.config.pricelists)}selected{/if}>{$pricelist}</option>
                      {/foreach}
                  </select>
               </div>
            </div>
         </div>
      </div>
   </div>
</div>
