  {% include 'header.twig' %}
  
  <style>
    @media (min-width: 768px)
.nav-tabs.nav-justified>li>a {
    /* border-bottom: 1px solid #ddd; */
    border-radius: 4px 4px 0 0;
}
.bg-refill {
    border-radius: 5px;
    background: #0d5bd9;
    color:white;
}
</style>
  
    <div id="page-wrapper">
      <div class="inner-page-wrapper"><script type="text/javascript" src="https://code.jquery.com/jquery-1.12.4.min.js">
      </script> 
 <script>
  	function copyToClipboard(element) {
      var $temp = $("<input>");
      $("body").append($temp);
      $temp.val($(element).text()).select();
      document.execCommand("copy");
      $temp.remove();
     }
</script>
<style>
  .width-service-name {
    min-width: 329px;
    width: 329px !important;
  } 
</style>

<div class="container-fluid service-page order-page">
  <div class="row">
    <div class="col-lg-12">
      <div class="well">
      <form class="search" action="/orders" method="get" id="history-search">
        <div class="input-group">
          <input type="text" name="search" class="form-control" value="" placeholder="Search orders">
          <span class="input-group-btn">
            <button type="submit" class="btn btn-default"><i class="fa fa-search" aria-hidden="true"></i></button>
          </span>
        </div>
      </form>
        </div>
      <div class="well">
        <div class="order-title">
          <div class="dash-title">
            <h2>Orders</h2>
          </div>
          <ul class="nav nav-pills">
              <li class="active"><a href="/orders"><i class="fas fa-list-ul"></i> All</a></li>
              <li ><a href="/orders/pending"><i class="far fa-pause-circle"></i> Pending</a></li>
              <li ><a href="/orders/inprogress"><i class="fas fa-redo"></i> In progress</a></li>
              <li ><a href="/orders/completed"><i class="fas fa-check-double"></i> Completed</a></li>
              <li ><a href="/orders/partial"><i class="fas fa-check"></i> Partial</a></li>
              <li ><a href="/orders/processing"><i class="fas fa-chart-line"></i> Processing</a></li>
              <li ><a href="/orders/canceled"><i class="far fa-times-circle"></i> Canceled</a></li>
              <li>
            </ul>
        </div>
        
        <div class="table-responsive">
          <table class="table ">
     <thead>
                           <tr class="row100 head">
                              <th class="column100 column1" data-column="column1">ID</th>
                              <th class="column100 column2" data-column="column2">Date</th>
                              <th class="column100 column3" data-column="column3">Link</th>
                              <th class="column100 column4" data-column="column4">Charge</th>
                              <th class="column100 column5" data-column="column5">Start count</th>
                              <th class="column100 column6" data-column="column6">Quantity
                              </th>
                              <th class="column100 column7" data-column="column7">Service</th>
                              <th class="column100 column8" data-column="column8">Status</th>
                              <th class="column100 column9" data-column="column9">Remains</th>
                              <th class="column100 column9" data-column="column9">Refill</th>                              
                           </tr>
                        </thead>
                        <tbody>
                           {% for order in orders %}
                           <tr>
                              <td>{{ order['id'] }}</td>
                              <td>{{ order['date'] }}</td>
                              <td class="width-40">{{ order['link'] }}</td>
                              <td>{{ order['charge'] }}</td>
                              <td class="nowrap">{{ order['start_count'] }}</td>
                              <td>{{ order['quantity'] }}</td>
                              <td>{{ order['service'] }}</td>
                              <td><span class="bg-{{ order['status']|lower }}">{{ order['status'] }}</td>
                              </span>
                              <td>{{ order['remains'] }}</td>
                              
             {% if order['status'] == "Completed"    %}
              
               {% if order['refill'] == 1   %}
<td>
   <form action="" method="post" id="history-search">
      <input type="hidden" name="order_id" value="{{ order['id'] }}" /> 
      <div style="display:inline-block;"  class="tooltip-wrapper" data-toggle={% if order['show_refill'] == 0 %} 
      tooltip
      {% endif %} data-placement="top" title=""  data-original-title="Next Refill will be available after 24 Hours"
      >
      <input style="pointer-events:{% if order['show_refill'] == 0 %} none; {% endif %}"  {% if order['show_refill'] == 0 %}  disabled  {% endif %}    id="refill-button"  class=" btn btn-actions bg-refill" style="display:inline;background: #0d5bd9; color: white;" type="submit" value="Refill" name="refill">
      </div>
   </form>
</td>
               {% endif %}
               {% endif %}                              
                           </tr>
                           {% endfor %}
                        </tbody>
        </table>
      </div>

      {% if pagination["count"] > 1 %}
        <ul class="pagination">

          {% if pagination["current"] != 1 %}
            <li>
              <a href="orders/{{ status }}/{{ pagination["previous"] }}{% if search %}?search={{ search }}{% endif %}" aria-label="Previous">
                <span aria-hidden="true">«</span>
              </a>
            </li>
          {% endif %}

          {% set r, l = 3, 3 %}

          {% if pagination['current'] == 1 %}
            {% set r = 7 %}
          {% endif %}

          {% if pagination['current'] == 2 %}
            {% set r = 5 %}
          {% endif %}

          {% if pagination['current'] >= pagination['count'] %}
            {% set l = 5 %}
          {% endif %}

          {% for page in 1..pagination["count"] %}
            {% if page >= (pagination['current']-l) and page <= (pagination['current']+r) %}
              <li{% if page == pagination['current'] %} class="active" {%endif%}><a href="orders/{{ status }}/{{ page }}{% if search %}?search={{ search }}{% endif %}">{{ page }}</a></li>
            {%endif%}
          {% endfor %}

          {% if pagination['current'] < pagination['count'] %}
            <li>
              <a href="orders/{{ status }}/{{ pagination['next'] }}{% if search %}?search={{ search }}{% endif %}" aria-label="Next">
                <span aria-hidden="true">»</span>
              </a>
            </li>
          {% endif %}

        </ul>
      {% endif %}

    </div>
  </div>
</div>


{% include 'footer.twig' %}
