<div id="incomaker" class="tab-pane boxStatic box">

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

   <div id="incomaker_settings">
      <div class="form-group">
         <div class="col-md-1 control-label"><label>API Key</label></div>
         <div class="col-md-6">
            <input type="text" class="form-control input-sm" name="incomaker[api_key]" size="30" maxlength="255"
                   value="{$dbcfg.incomaker.api_key}" readonly>
         </div>
      </div>
       <div class="form-group">
         <div class="col-md-1 control-label"><label>Account UUID</label></div>
         <div class="col-md-6">
            <input type="text" class="form-control input-sm" name="incomaker[account_uuid]" size="30" maxlength="255"
                   value="{$dbcfg.incomaker.account_uuid}" readonly>
         </div>
      </div>
       <div class="form-group">
         <div class="col-md-1 control-label"><label>Plugin UUID</label></div>
         <div class="col-md-6">
            <input type="text" class="form-control input-sm" name="incomaker[plugin_uuid]" size="30" maxlength="255"
                   value="{$dbcfg.incomaker.plugin_uuid}" readonly>
         </div>
      </div>
   </div>

   {get_contexts currency=1 language=1 assign="contexts"}
   <div class="panel-group panel-group-lists">
      <div class="panel panel-default">
         <div class="panel-heading {if !empty($dbcfg.incomaker.api_key)}collapsed{/if} panel-heading-flex"
              data-toggle="collapse" data-target="#incomaker_plugin">
            <p style="margin-left: 10px;"><strong>Incomaker plugin</strong></p>
         </div>
         <div id="incomaker_plugin" class="panel-collapse collapse {if empty($dbcfg.incomaker.api_key)}in{/if}">
            <div class="panel-body">
               <div class="form-group">
                  <div class="col-md-2 control-label"><label>Uživatelské jméno</label></div>
                  <div class="col-md-3">
                     <input type="text" class="form-control input-sm" name="incomaker[login]" size="30" maxlength="255"
                            value="" placeholder="wpj account">
                  </div>
                  <div class="col-md-2 control-label"><label>Měna</label></div>
                  <div class="col-md-2">
                     <input type="text" class="form-control input-sm" name="incomaker[currency]" size="30" maxlength="255"
                            value="{$contexts.currency->getDefaultId()}" readonly>
                  </div>
               </div>
               <div class="form-group">
                  <div class="col-md-2 control-label"><label>Heslo</label></div>
                  <div class="col-md-3">
                     <input type="password" class="form-control input-sm" name="incomaker[password]" size="30" maxlength="255"
                            value="" autocomplete="new-password">
                  </div>
                  <div class="col-md-2 control-label"><label>Jazyk</label></div>
                  <div class="col-md-2">
                     <input type="text" class="form-control input-sm" name="incomaker[language]" size="30" maxlength="255"
                            value="{$contexts.language->getDefaultId()}" readonly>
                  </div>
               </div>
               <div class="form-group">
                  <div class="col-md-2 control-label"><label>URL adresa e-shopu</label></div>
                  <div class="col-md-3">
                     <input type="text" class="form-control input-sm" name="incomaker[url]" size="30" maxlength="255"
                            value="{$dbcfg.incomaker.url|default:$cfg.Addr.full}" placeholder="{$cfg.Addr.full}">
                  </div>
                  <div class="col-md-2 control-label"><label>Časová zóna</label></div>
                  <div class="col-md-2">
                     <input type="text" class="form-control input-sm" name="incomaker[timeZone]" size="30" maxlength="255"
                            value="{$dbcfg.incomaker.timeZone|default:date_default_timezone_get()}" readonly>
                  </div>
               </div>
               <div class="form-group">
                  <div class="col-md-2 control-label"><label>URL adresa feedů</label></div>
                  <div class="col-md-3">
                     {$defaultUrl = "{$cfg.Addr.full}_incomaker/feed/"}
                     <input type="text" class="form-control input-sm" name="incomaker[serverPalpUrl]" size="30" maxlength="255"
                            value="{$dbcfg.incomaker.serverPalpUrl|default:$defaultUrl}" placeholder={$defaultUrl}>
                  </div>
                  <div class="col-md-2 control-label"><label>Verze pluginu</label></div>
                  <div class="col-md-2">
                     <input type="text" class="form-control input-sm" name="incomaker[pluginVersion]" size="30" maxlength="255"
                            value="{$dbcfg.incomaker.pluginVersion|default:'1.0'}" readonly>
                  </div>
               </div>
               <div class="form-group">
                  <div class="col-md-2 col-md-offset-2">
                     <input type="hidden" name="incomaker[platformName]" value="Kupshop">
                     <button type="submit" class="btn btn-success btn-block" name="acn" value="incomakerPlugin" disabled>
                        {if empty($dbcfg.incomaker.api_key)}Register{else}Update{/if} plugin
                     </button>
                     <script>
                         $('#incomaker_plugin').on('change', 'input', function () {
                             $('#incomaker_plugin button').prop("disabled", false);
                             $('#incomaker_plugin input').each(function() {
                                 this.value = this.value.trim();
                                 if (this.value == '') {
                                     $('#incomaker_plugin button').prop("disabled", true);
                                     return;
                                 }
                             });
                         });
                     </script>
                  </div>
               </div>
            </div>
         </div>
      </div>
      {ifmodule PRODUCTS_PARAMETERS}
      <hr>
      <div class="panel panel-default">
         <div class="panel-heading {if empty($dbcfg.incomaker.tags)}collapsed{/if} panel-heading-flex"
              data-toggle="collapse" data-target="#incomaker_tags">
            <p style="margin-left: 10px;"><strong>Incomaker product tags</strong></p>
         </div>
         <div id="incomaker_tags" class="panel-collapse collapse {if !empty($dbcfg.incomaker.tags)}in{/if}">
            <div class="panel-body">
               <div class="form-group">
                  <label class="col-md-2 control-label">Vyberte parametry</label>
                  <div class="col-md-6">
                        <select multiple="multiple" class="selecter" id="incomaker_tags_params"
                                data-type="parameters" data-autocomplete="parameters" data-preload="parameters"
                                name="incomaker[tags][]">
                           {foreach $dbcfg.incomaker.tags as $paramID}
                              <option value="{$paramID}" selected>{$paramID}</option>
                           {/foreach}
                        </select>
                  </div>
               </div>
            </div>
         </div>
      </div>
      {/ifmodule}
      <hr>
      <div class="row">
         {ifmodule PRODUCTS_RELATED}
            <div class="col-md-2 control-label"><label>{'sectionCategorizationRelated'|translate:'products'}</label></div>
            <div class="col-md-3">
               {print_toggle nameRaw='incomaker[products_related]' value=$dbcfg.incomaker.products_related}
            </div>
         {/ifmodule}
         <div class="col-md-3 control-label"><label>Vkládat tag se slevou (discountRate)</label></div>
         <div class="col-md-3">
            {print_toggle nameRaw='incomaker[default_discount_tag]' value=$dbcfg.incomaker.default_discount_tag}
         </div>
      </div>
      {ifmodule PRODUCTS_RELATED__TYPES}
         <div class="row">
            <div class="col-md-2 control-label"><label>{'related_type'|translate:'productsRelatedTypes'}</label></div>
            <div class="col-md-3">
               <select data-autocomplete="productsRelatedTypes" data-preload="productsRelatedTypes"
                       name="incomaker[related_type][]" multiple="multiple"
                       class="selecter selecter-ajax">
                  {foreach $dbcfg.incomaker.related_type as $type}
                     <option value="{$type}" selected>{$type}</option>
                  {/foreach}
               </select>
            </div>
         </div>
      {/ifmodule}
      {if findModule('oss_vats') || findModule('pricelists')}
      <hr>
      <div class="panel panel-default">
         <div class="panel-heading {if empty($dbcfg.incomaker.oss_prices)}collapsed{/if} panel-heading-flex"
              data-toggle="collapse" data-target="#incomaker_oss_prices">
            <p style="margin-left: 10px;"><strong>Incomaker product prices</strong></p>
         </div>
         <div id="incomaker_oss_prices" class="panel-collapse collapse {if !empty($dbcfg.incomaker.oss_prices)}in{/if}">
            <div class="panel-body">
               <div class="form-group">
                  <div class="col-md-2">
                     <a href="#" data-form-add class="btn btn-success btn-block"><span class="glyphicon glyphicon-plus"></span>&nbsp;{'titleAdd'|translate:'countries'}</a>
                  </div>
                  <div class="col-md-10">
                     <div class="panel-group panel-group-lists">
                        {$incomaker_oss_prices = [[]]}
                        {if $dbcfg.incomaker.oss_prices}
                           {$incomaker_oss_prices = $incomaker_oss_prices + $dbcfg.incomaker.oss_prices}
                        {/if}
                        {foreach $incomaker_oss_prices as $key => $row}
                           <div class="panel" {if $key == 0}data-form-new style="display:none" {else}data-form-item{/if}>
                              <div class="row bottom-space">
                                 <div class="col-md-2 control-label"><label>{'country'|translate:'orders'}</label></div>
                                 <div class="col-md-2">
                                    <select name="incomaker[oss_prices][{$key}][id_country]" class="selecter"
                                            data-type="countries" data-autocomplete="countries" data-preload="countries"
                                            data-placeholder="{'selectCountry'|translate:'orders'}">
                                       <option value="{$row.id_country}" selected>{$row.id_country}</option>
                                    </select>
                                 </div>
                                 <div class="col-md-1 control-label"><label>{'currency'|translate:'orders'}</label></div>
                                 <div class="col-md-2">
                                    <select name="incomaker[oss_prices][{$key}][id_currency]" class="selecter"
                                            data-type="currencies" data-autocomplete="currencies" data-preload="currencies"
                                            data-placeholder="{'selectCountry'|translate:'orders'}">
                                       <option value="{$row.id_currency}" selected>{$row.id_currency}</option>
                                    </select>
                                 </div>
                                 {ifModule PRICELISTS}
                                 <div class="col-md-1 control-label"><label>{'priceList'|translate:'users'}</label></div>
                                 <div class="col-md-3">
                                    <select name="incomaker[oss_prices][{$key}][id_pricelist]" class="selecter"
                                            data-type="priceLists" data-autocomplete="priceLists" data-preload="priceLists"
                                            data-placeholder="{'defaultPriceList'|translate:'productsFilter'}">
                                       {if $row.id_pricelist}
                                          <option value="{$row.id_pricelist}" selected>{$row.id_pricelist}</option>
                                       {/if}
                                    </select>
                                 </div>
                                 {/ifModule}
                                 <div class="col-md-1">
                                    <a class="btn-sm btn btn-danger" data-form-delete>
                                       <input class="hidden" type="checkbox" name="incomaker[oss_prices][{$key}][delete]"/>
                                       <span class="glyphicon glyphicon-remove"></span>
                                    </a>
                                 </div>
                              </div>
                           </div>
                        {/foreach}
                     </div>
                  </div>
               </div>
               <script type="application/javascript">
                  initForm({
                     selector: '#incomaker_oss_prices',
                     beforeAdd: function(original){
                        var $form = original();
                        preloadAutocompletes($form);
                     }
                  });
               </script>
            </div>
         </div>
      </div>
      {/if}
   </div>

</div>
