<div id="flapMailerlite" class="tab-pane fade in boxFlex">
   {insert_orders_filter filterName='flapStatsOrderMailerlite' saveFilter=true}
   {include "block.productsFilter.tpl" saveFilter=true filterName='flapStatsProductMailerlite'}
   {insert_users_filter filterName='flapStatsUsersMailerLite' saveFilter=true}


   {$barName = 'Mailerlite'}
   <div class="row bottom-space" data-filter-name="interval{$barName}">
      <div class="col-xs-12">
         <div class="panel panel-primary">
            <div class="panel-body">
               <div class="form-group">
                  <div class="col-md-1 control-label"><label>Platnost</label></div>
                  <div class="col-md-1 radio" style="width: auto; padding-right: 0px;">
                     <input type="radio" class="check" name="actionTypeSet" value="registered" id="registered" checked/>
                     <label for="registered"></label>
                  </div>
                  <div class="col-md-1">
                     <span class="help-block">Všichni uživatelé
                        <a class="help-tip" style="position:relative;" data-toggle="tooltip" title=""
                           data-original-title="Exportuje množinu všech uživatelů."><i
                           class="bi bi-question-circle"></i></a>
                     </span>
                  </div>
                  <div class="col-md-1 radio" style="width: auto; padding-right: 0px;">
                     <input type="radio" class="check" name="actionTypeSet" value="newsletter" id="newsletter"/>
                     <label for="newsletter"></label>
                  </div>
                  <div class="col-md-1">
                     <span class="help-block">Mají newsletter
                        <a class="help-tip" style="position:relative;" data-toggle="tooltip" title=""
                           data-original-title="Exportuje množinu uživatelů, kteří mají přihlášený newsletter."><i
                           class="bi bi-question-circle"></i></a>
                     </span>
                  </div>
                  <div class="col-md-1 radio" style="width: auto; padding-right: 0px;">
                     <input type="radio" class="check" name="actionTypeSet" value="just_buy" id="just_buy"/>
                     <label for="just_buy"></label>
                  </div>
                  <div class="col-md-1">
                     <span class="help-block">Pouze nakoupili
                        <a class="help-tip" style="position:relative;" data-toggle="tooltip" title=""
                           data-original-title="Exportuje množinu uživatelů, kteří nemají přihlášený newsletter, nemají registraci a mají alespon jednu objednávku."><i
                           class="bi bi-question-circle"></i></a>
                     </span>
                  </div>
                  <div class="col-md-2 pull-left">
                     <input type="button" class="btn btn-primary btn-block btn-sm"
                            value="{'show'|translate}" data-btn-show-{$barName} data-btn-submit>
                  </div>
               </div>
               <script type="text/javascript">
                  wpj.formUtils.initFormSave($('[data-filter-name="interval{$barName}"]'), 'interval{$barName}');
               </script>
            </div>

            {if $graphs}
               <script type="text/javascript">
                  $(document).on('click', '[data-btn-show-{$barName}]', function () {
                     showGraphsArea($(this));

                     {foreach $graphs as $graph}
                     get{$graph}Graph($('[name=interval{$barName}]:checked').val());
                     {/foreach}
                  });
               </script>
            {/if}
         </div>
      </div>
   </div>

   <div class="row bottom-space" id="products" data-display-area="mailerlite">
      <div class="col-md-12">
         <div id="userdata_content">
            <div class="panel panel-default panel-sm">
               <div class="panel-heading">
                  <div class="pull-right">
                     {'countValue'|translate}&nbsp{$tab.data.rowNumber}
                  </div>
                  <a class="help-tip" style="position:relative; float:right;margin-top: -2px;margin-right: 10px" data-toggle="tooltip"
                     title="{'userDataStats'|translate}">
                     <i class="bi bi-question-circle"></i>
                  </a>
                  <h3 class="panel-title">{'userDataStats'|translate}</h3>
               </div>
               <table class="table">
                  <tr>
                     <th>{'userName'|translate}</th>
                     <th>{'userSurname'|translate}</th>
                     <th>{'userEmail'|translate}</th>
                     <th>{'userPhone'|translate}</th>
                     <th>{'isRegistered'|translate}</th>
                     <th>{'countOrders'|translate}</th>
                     <th>{'sumMoney'|translate}</th>
                     <th>{'avgMoney'|translate}</th>
                     <th>{'firstShop'|translate}</th>
                     <th>{'lastShop'|translate}</th>
                     <th>{'getNews'|translate}</th>
                  </tr>
                  {foreach $tab.data.usersData as $item}
                     <tr style="background-color: #f9f9f9; border-top: 2px solid #ddd !important; ">
                        <td>{$item.name}</td>
                        <td>{$item.surname}</td>
                        <td><a href="javascript:nw('user', '{$item.id}');">{$item.email}</a></td>
                        <td>{$item.phone}</td>
                        <td>{if empty($item.date_reg) || $item.date_reg == '0000-00-00 00:00:00'}N{else}Y{/if}</td>
                        <td>{$item.count}</td>
                        <td>{$item.price|format_price:"ceil=no;decimal=dynamic"}</td>
                        <td>{$item.average_price|format_price:"ceil=no;decimal=dynamic"}</td>
                        <td>{$item.mindate}</td>
                        <td>{$item.maxdate}</td>
                        <td>{if $item.get_news == 'Y'}Y{else}N{/if}</td>
                     </tr>
                  {/foreach}
               </table>
            </div>
            <div class="row">
               <div class="col-md-2 pull-right">
                  <input type="button" class="btn btn-primary btn-block btn-sm"
                         value="{'export'|translate}" data-btn-export-Mailerlite data-btn-submit>
               </div>
            </div>
         </div>
      </div>
   </div>
</div>

<script type="application/javascript">
   $(document).on('click', '[data-btn-show-mailerlite]', function() {
      reloadDivMailerlite();
      showGraphsArea($(this));
   });

   $(document).on('click', '[data-btn-export-mailerlite]', function() {
      var paramsString = concatParams({
         type: 'stats',
         acn: 'getMailerlite'
      }, '#flapMailerlite');

      window.location.href = 'launch.php?s=board.php&ajax=1&' + paramsString;
   });

   function reloadDivMailerlite() {
      reloadDiv('#userdata_content', {
         type: 'stats',
         showUsersStat: 1
      }, '#flapMailerlite');
   }
</script>
