<div class="row">
   <div class="col-md-3">
      <div class="wpj-form-group">
         <div class="d-flex align-items-center">
            {print_toggle nameRaw="data[data][active_type]" value=$body.data.data.active_type}
            <label>
               {'active_title'|translate}
            </label>
         </div>
      </div>
   </div>

   <div class="col-md-3">
      <div class="wpj-form-group">
         <div class="input-group">
            <input type="text" class="form-control input-sm action-selector" name="data[data][active_action_days]" maxlength="3" id="active_action_days"
                   value="{$body.data.data.active_action_days}" placeholder="14" {if $body.data.data.active_type != 'Y'}disabled{/if}>
            <label for="active_action_days" class="input-group-addon">
               {'Day'|translate:'settings'}
            </label>
         </div>
      </div>
   </div>

   {* Pokud se ten select nahore disabluje, tak se ani neodesle, takze ho musim tady poslat aspon jako hidden input  *}
   {if $body.data.data.active_type != 'X' && $body.data.data.active_action_type}
      <input type="hidden" name="data[data][active_action_type]" value="{$body.data.data.active_action_type}">
    {/if}

   <div class="col-md-3">
      <div class="wpj-form-group">
         <select name="data[data][active_action_type]" class="selecter action-selector" {if $body.data.data.active_type != 'X'}disabled{/if}>
            <option value="">{'selectAction'|translate}</option>
            <option value="from_product_creation" {$body.data.data.active_action_type|selected:'from_product_creation'}>
                {'from_product_creation'|translate}
            </option>
            {ifmodule STOCK_IN}
                <option value="from_product_stock_in" {$body.data.data.active_action_type|selected:'from_product_stock_in'}>
                    {'from_product_stock_in'|translate}
                </option>
            {/ifmodule}
         </select>
      </div>
   </div>
</div>

<div class="row">
   <div class="col-md-12">
      <div class="wpj-form-group">
         <div class="d-flex align-items-center">
            {print_toggle nameRaw="data[cron_assignment]" value=$body.data.cron_assignment}
            <label>{'cron_assignment'|translate}
               <a class="help-tip" data-toggle="tooltip" title="{'cron_assignment_info'|translate}">
                  <i class="bi bi-question-circle"></i>
               </a>
            </label>
         </div>
      </div>
   </div>
</div>
<div class="row">
   <div class="col-md-12">
      <div data-product-filter{if $body.data.cron_assignment != 'Y'} style="display: none;"{/if}>
         {include "block.productsFilter.tpl" filter=$body.data.data.product_filter filterName='flapAutomaticLabelAssignment'}
      </div>
   </div>
</div>

<script>
   $("input[name='data[data][active_type]']").on("change", function () {
      const $inputs = $(".action-selector");
      console.log($(this).is(':checked'));
      $inputs.prop("disabled", !$(this).is(':checked'));
      $inputs.trigger('chosen:updated')
   });

   $("input[name='data[cron_assignment]']").on("change", function () {
      $('[data-product-filter]').slideToggle();
   });
</script>
