<?php
$this->load->view('partials/report_start', $this->data);
$report = isset($report) ? $report : array();
$limit = isset($limit) ? $limit : 10;
$fdate = isset($fdate) ? $fdate : date('d-m-Y', strtotime('-365 days'));
$tdate = isset($tdate) ? $tdate : date('d-m-Y');
?>
<form method="post">
  <div class="row filter-row align-items-end mb-3">
    <div class="col-md-2">
      <div class="form-group mb-0">
        <label>From Date</label>
        <input type="text" class="form-control js-date" name="fdate" value="<?php echo htmlspecialchars($fdate); ?>" required placeholder="dd-mm-yyyy" autocomplete="off">
      </div>
    </div>
    <div class="col-md-2">
      <div class="form-group mb-0">
        <label>To Date</label>
        <input type="text" class="form-control js-date" name="tdate" value="<?php echo htmlspecialchars($tdate); ?>" required placeholder="dd-mm-yyyy" autocomplete="off">
      </div>
    </div>
    <div class="col-md-2">
      <div class="form-group mb-0">
        <label>Show top</label>
        <select name="limit" class="form-control">
          <?php foreach (array(10, 25, 50) as $n) { ?>
            <option value="<?php echo $n; ?>" <?php echo ((int) $limit === $n) ? 'selected' : ''; ?>><?php echo $n; ?></option>
          <?php } ?>
        </select>
      </div>
    </div>
    <div class="col-md-3">
      <p class="mb-0 text-muted small mt-4">Most active borrowers in the selected period.</p>
    </div>
    <div class="col-md-3">
      <?php $this->load->view('partials/report_actions'); ?>
    </div>
  </div>
<?php if (!empty($searched)) { ?>
  <div class="report-results-toolbar">
    <p class="report-summary mb-0">
      Top <strong><?php echo count($report); ?></strong> user(s)
      from <?php echo htmlspecialchars($fdate); ?> to <?php echo htmlspecialchars($tdate); ?>
    </p>
    <?php $this->load->view('partials/report_exports'); ?>
  </div>
  <?php
  $this->load->view('partials/report_datatable', array(
      'columns' => array(
          'Rank' => 'RANK',
          'Id No' => 'ID_No',
          'Name' => 'Name',
          'Designation' => 'Designation',
          'Count' => 'Count',
      ),
      'rows' => $report,
      'table_id' => 'topUsersTable',
  ));
}
?>
</form>
<?php $this->load->view('partials/report_end'); ?>
