{{ header }}
<style type="text/css">
.table tr:nth-child(odd),.table tr:nth-child(even) {
    background-color: unset !important;
}
.table thead th {
    border-bottom: 2px solid #f1ae004d;
}

.table-bordered td, .table-bordered th {
   border-color: #f1ae004d !important;
}
.ltn__pagination ul li a {
    height: auto;
    width: 22px;
    line-height: 0px;
    border: unset;
}
.ltn__pagination ul li {
    margin-top: 0px;
}
</style>
<div id="account-reward" class="container">
  <ul class="breadcrumb">
    {% for breadcrumb in breadcrumbs %}
    <li><a href="{{ breadcrumb.href }}">{{ breadcrumb.text }}</a></li>
    {% endfor %}
  </ul>
  <div class="row">{{ column_left }}
    {% if column_left and column_right %}
    {% set class = 'col-sm-6' %}
    {% elseif column_left or column_right %}
    {% set class = 'col-sm-9' %}
    {% else %}
    {% set class = 'col-sm-12' %}
    {% endif %}
    <div id="content" class="{{ class }}">{{ content_top }}
      <h2>{{ heading_title }}</h2>

      {% if locked %}
      <div class="row justify-content-center mt-4">
        <div class="col-sm-6 col-md-4">
          <div class="card p-4" style="border:1px solid #f1ae004d;">
            <h5 class="mb-3">Enter your password to view your team</h5>
            <div id="direct-unlock-error" class="alert alert-danger" style="display:none;"></div>
            <div class="form-group">
              <input type="password" id="direct-password" class="form-control" placeholder="Password" />
            </div>
            <button id="direct-unlock-btn" class="btn btn-primary btn-block mt-2">View Team</button>
          </div>
        </div>
      </div>
      <script>
        document.getElementById('direct-unlock-btn').addEventListener('click', function() {
          var password = document.getElementById('direct-password').value;
          var errorEl  = document.getElementById('direct-unlock-error');
          errorEl.style.display = 'none';
          fetch('{{ unlock_url }}', {
            method: 'POST',
            headers: {'Content-Type': 'application/x-www-form-urlencoded'},
            body: 'password=' + encodeURIComponent(password)
          })
          .then(function(r){ return r.json(); })
          .then(function(data) {
            if (data.success) {
              window.location = '{{ direct_base_url }}&_auth=' + data.token;
            } else {
              errorEl.textContent = data.error || 'Wrong password';
              errorEl.style.display = 'block';
            }
          });
        });
        document.getElementById('direct-password').addEventListener('keydown', function(e) {
          if (e.key === 'Enter') document.getElementById('direct-unlock-btn').click();
        });
      </script>
      {% else %}
      <p>{{ text_total }} <b>{{ total }}</b>.</p>
      <div class="table-responsive">
        <table class="table table-bordered table-hover" >
          <thead>
            <tr class="table_header" style="background:#fffcf4 !important;">
              <th>{{ column_date_added }}</th>
              {#<th>{{ column_username }}</th>#}
              <th>{{ column_name }}<br>({{ column_rank }})</th>
              <th>Last month Self Business BP</th>
              <th>Current month Self Business BP</th>
              <th>Last month Group Business BP</th>
              <th>Current month Group Business BP</th>
              {#<th>{{ column_rank }}</th>#}
              
            </tr>
          </thead>
          <tbody>
          
          {% if directs %}
          {% for direct in directs %}
          <tr>
            <td>{{ direct.date_added }}</td>
            <td>{{ direct.name }}({{ direct.username }})<br>{{ direct.rank }}</td>
            <td>{{ direct.last_self_business }}</td>
            <td>{{ direct.curr_self_business }}</td>
            <td>{{ direct.last_group_business }}</td>
            <td>{{ direct.curr_group_business }}</td>
          </tr>
          {% endfor %}
          {% else %}
          <tr>
            <td class="text-center" colspan="8">{{ text_empty }}</td>
          </tr>
          {% endif %}
            </tbody>
          
        </table>
      </div>
         <div class="row">
        <div class="col-sm-6 mt-3 text-center text-sm-left">{{ results }}</div>
        <div class="col-sm-6 mt-3 "><div class="ltn__pagination-area">
          <div class="ltn__pagination  text-center text-sm-right">
              {{ pagination }}
          </div>
        </div></div>
      </div>
      <div class="buttons clearfix  mb-4">
        <div class="pull-right"><a href="{{ continue }}" class="btn btn-primary">{{ button_continue }}</a></div>
      </div>
      {% endif %}

      {{ content_bottom }}</div>
    {{ column_right }}</div>
</div>
{{ footer }}