{extends file="[shared]/window.tpl"}

{block tabs}
    {windowTab id='flapMain'}

    {if $body.data.id}
        {windowTab id='flapProducts'}
        {windowTab id='flapDiscountLevels'}
        {windowTab id='flapDates'}
    {/if}
{/block}

{block tabsContent}
   <div id="flapMain" class="tab-pane fade active in boxStatic box">
      <div class="row">
         <div class="col-xs-1">
            <div class="wpj-form-group">
               <label for="id_preorder">Číslo</label>
               <input id="id_preorder" class="form-control text-center" disabled value="{$body.data.id}" style="max-width: 3em;">
            </div>
         </div>
         <div class="col-xs-5">
            <div class="wpj-form-group">
               <label>
                   {'name'|translate}
                  <a class="help-tip" data-html="true" data-placement="right"
                     data-toggle="tooltip" title="" data-original-title="Zobrazí se uživatelům v prostředí předobjednávek">
                     <i class="bi bi-question-circle"></i>
                  </a>
               </label>
               <input type="text" name="data[name]" id="name" class="form-control" value="{$body.data.name}">
            </div>
         </div>
         <div class="col-xs-6">
            <div class="wpj-form-group" id="date-fields">
               <label>{'usersGroup'|translate}</label>
               <select
                  name="data[settings][users_groups][]"
                  multiple="multiple"
                  class="selecter"
                  data-autocomplete="users_groups"
                  data-preload="usersGroups"
               >
                   {foreach $body.data.settings.users_groups as $group}
                      <option value="{$group}" selected>{$group}</option>
                   {/foreach}
               </select>
            </div>
         </div>
         {block "custom-data"}{/block}
      </div>
      <div class="row">
         <div class="col-xs-6">
            <div class="wpj-form-group">
               <label>{'base'|translate} {lcfirst('pricelist'|translate)}</label>
               <select
                  name="data[id_pricelist]"
                  class="selecter"
                  data-autocomplete="priceLists"
                  data-preload="priceLists"
               >
                  <option value="">{'pricelistEmptyChoice'|translate}</option>
                   {if $body.data.id_pricelist}
                      <option value="{$body.data.id_pricelist}" selected>{$body.data.id_pricelist}</option>
                   {/if}
               </select>
            </div>
         </div>
         <div class="col-xs-6">
            <div class="wpj-form-group">
               <label>{'base'|translate} {lcfirst('priceLevel'|translate)}</label>
               <select
                  name="data[id_price_level]"
                  class="selecter"
                  data-autocomplete="priceLevels"
                  data-preload="priceLevels"
               >
                  <option value="">{'priceLevelStandard'|translate:'users'}<option>
                       {if $body.data.id_price_level}
                  <option value="{$body.data.id_price_level}" selected>{$body.data.id_price_level}</option>
                   {/if}
               </select>
            </div>
         </div>
      </div>
      <div class="row">
         <div class="col-xs-6">
            <div class="wpj-form-group">
               <label for="input--min_price">{'minPrice'|translate}</label>
               <div class="input-group">
                  <input id="input--min_price" type="text" class="form-control" name="data[min_price]"
                         value="{if $body.data.min_price}{$body.data.min_price->asFloat()|string_format:"%.2f"}{/if}">
                  <span class="input-group-addon">{$dbcfg.currency}</span>
                  <span class="input-group-addon">{'withoutTax'|translate:'choice'}</span>
               </div>
            </div>
         </div>
      </div>
   </div>

   <div id="flapProducts" class="tab-pane fade boxFlex">
       {$productsSortable = true}
       {include 'block.productsFilter.tpl' filter=$body.data.settings.products_filter
       filterInputName='data[settings][products_filter]' filterName='products_filter'}
   </div>

   <div id="flapDiscountLevels" class="tab-pane fade boxStatic box">
      <div class="row bottom-space">
         <div class="col-xs-3">
            <button type="button" class="btn btn-block btn-success" data-form-add>
               <i class="bi bi-plus-lg m-r-1"></i>{'addDynamicPrice'|translate}
            </button>
         </div>
      </div>
      <div class="wpj-panel wpj-panel-default">
         <div class="wpj-panel-heading">
            <div class="row">
               <div class="col-xs-2">
                  <strong class="small">{'priceFrom'|translate}</strong>
               </div>
               <div class="col-xs-2">
                  <strong class="small">{'priceTo'|translate}</strong>
               </div>
               <div class="col-xs-3">
                  <strong class="small">{'priceLevel'|translate}</strong>
               </div>
               <div class="col-xs-3">
                  <strong class="small">{'pricelist'|translate}</strong>
               </div>
            </div>
         </div>

         <div class="wpj-list-group">
            <div class="wpj-list-group-item" style="display: none;" data-form-new>
               <div class="row">
                  <div class="col-xs-2">
                     <div class="input-group">
                        <input class="form-control" name="data[settings][dynamic_prices][@][price_from]"
                               placeholder="{'priceFrom'|translate}">
                     </div>
                  </div>
                  <div class="col-xs-2">
                     <div class="input-group">
                        <input class="form-control" name="data[settings][dynamic_prices][@][price_to]"
                               placeholder="{'priceTo'|translate}">
                     </div>
                  </div>
                  <div class="col-xs-3">
                     <select
                        class="selecter"
                        name="data[settings][dynamic_prices][@][id_price_level]"
                        data-autocomplete="priceLevels"
                     >
                        <option selected value="">{'priceLevelStandard'|translate:'users'}</option>
                     </select>
                  </div>
                  <div class="col-xs-3">
                     <select
                        class="selecter"
                        name="data[settings][dynamic_prices][@][id_pricelist]"
                        data-autocomplete="priceLists"
                     >
                        <option value="">{'pricelistEmptyChoice'|translate}</option>
                     </select>
                  </div>
                  <div class="col-xs-2 text-right">
                     <button type="button" class="btn btn-sm btn-danger" data-form-delete>
                        <i class="bi bi-trash"></i>
                     </button>
                  </div>
               </div>
            </div>
             {foreach $body.data.settings.dynamic_prices as $dynamicPrice}
                <div class="wpj-list-group-item" data-form-item>
                   <div class="row">
                      <div class="col-xs-2">
                         <div class="input-group">
                            <input class="form-control" name="data[settings][dynamic_prices][{$dynamicPrice@index}][price_from]"
                                   value="{$dynamicPrice.price_from}"
                                   placeholder="{'priceFrom'|translate}">
                         </div>
                      </div>
                      <div class="col-xs-2">
                         <div class="input-group">
                            <input class="form-control" name="data[settings][dynamic_prices][{$dynamicPrice@index}][price_to]"
                                   value="{$dynamicPrice.price_to}"
                                   placeholder="{'priceTo'|translate}">
                         </div>
                      </div>
                      <div class="col-xs-3">
                         <select
                            class="selecter"
                            name="data[settings][dynamic_prices][{$dynamicPrice@index}][id_price_level]"
                            data-autocomplete="priceLevels"
                            data-autocomplete-params="allow_empty=1"
                            data-preload="priceLevels"
                         >
                             {if $dynamicPrice.id_price_level}
                                <option selected value="{$dynamicPrice.id_price_level}">{$dynamicPrice.id_price_level}</option>
                             {/if}
                         </select>
                      </div>
                      <div class="col-xs-3">
                         <select
                            class="selecter"
                            name="data[settings][dynamic_prices][{$dynamicPrice@index}][id_pricelist]"
                            data-autocomplete="priceLists"
                            data-preload="priceLists"
                         >
                            <option value="">{'pricelistEmptyChoice'|translate}</option>
                             {if $dynamicPrice.id_pricelist}
                                <option selected value="{$dynamicPrice.id_pricelist}">{$dynamicPrice.id_pricelist}</option>
                             {/if}
                         </select>
                      </div>
                      <div class="col-xs-2 text-right">
                         <button type="button" class="btn btn-sm btn-danger" data-form-delete>
                            <i class="bi bi-trash"></i>
                         </button>
                      </div>
                   </div>
                </div>
             {/foreach}
         </div>
      </div>
   </div>

   <div id="flapDates" class="tab-pane fade active in boxStatic box">
      <div class="row bottom-space">
         <div class="col-xs-3">
            <a class="btn btn-block btn-success"
               href="javascript:nw('preordersDates', null, 'id_preorder={$body.data.id}');"><span class="bi bi-plus-lg m-r-1"></span>{'addPreorderDate'|translate}</a>
         </div>
      </div>
      <iframe class="on-demand boxFlex" height="600"
              data-src="launch.php?s=list.php&type=preordersDates&id_preorder[]={$body.data.id}"></iframe>
   </div>
{/block}
{block onready append}
   initForm({
      selector: '#flapDiscountLevels',
      jsonFriendly: true,
      beforeAdd(callback) {
         var $form = callback();
         window.preloadAutocompletes($form);

         return false;
      },
   });
{/block}
