{% include 'header.twig' %}
    <main><style> 
.nightmode a {
    color: #FFFFFF !important;
}
.authorized .btn.btn-primary{
  border-radius: 5px !important;
  margin-top: 5px;
  }

</style>
<div class="main_container" id="main_container">
     <div class="content_area">
      <div class="content">

          <div class="row">
               <div class="col-md-12">
                 <div class="card card_v2 mb-5">
                   <div class="card-body">
                    	
                   </div>
                 </div>
               </div>
             </div>
        <!-- page and other top info -->
     <div class="page_top_info" id="page_top_info">
      
     </div>

   
        
             <section id="defOrder">
                  <div class="container-fluid">
                    <div class="row">
                     <div class="col-md-12">
                     <div class="card card_v2">
                       <div class="card-body">
                         <form action="" method="get" id="history-search">
                           <div class="input-group">
                             <input name="search" class="form-control" placeholder="Search orders" type="text">
                             <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>
                     </div>
                      <div class="col-md-12">
                       
                        <div class="card card_v2">
                          <div class="card-body">
                        <nav class="nav nav-pills flex-column flex-sm-row gap-2" id="orders_menu">

                            <a {% if 'all' == status %}  class="flex-sm-fill text-sm-center nav-link active" {% endif %} class="flex-sm-fill text-sm-center nav-link" href="/orders"><span class="icon"><i class="fas fa-list"></i></span>All</a>

                            <a {% if 'pending' == status %}  class="flex-sm-fill text-sm-center nav-link active" {% endif %} class="flex-sm-fill text-sm-center nav-link" href="/orders/pending"><span class="icon"><i class="far fa-pause-circle"></i></span>Pending</a>


                            <a {% if 'inprogress' == status %}  class="flex-sm-fill text-sm-center nav-link active" {% endif %} class="flex-sm-fill text-sm-center nav-link  " href="/orders/inprogress"><span class="icon"><i class="fas fa-redo"></i></span>In progress</a>

                            <a {% if 'completed' == status %}  class="flex-sm-fill text-sm-center nav-link active" {% endif %} class="flex-sm-fill text-sm-center nav-link " href="/orders/completed"><span class="icon"><i class="fas fa-check-double"></i></span>Completed</a>

                            <a {% if 'partial' == status %}  class="flex-sm-fill text-sm-center nav-link active" {% endif %} class="flex-sm-fill text-sm-center nav-link " href="/orders/partial"><span class="icon"><i class="fas fa-check"></i></span>Partial</a>

                            <a {% if 'processing' == status %}  class="flex-sm-fill text-sm-center nav-link active" {% endif %} class="flex-sm-fill text-sm-center nav-link " href="/orders/processing"><span class="icon"><i class="fas fa-chart-line"></i></span>Processing</a>

                            <a {% if 'canceled' == status %}  class="flex-sm-fill text-sm-center nav-link active" {% endif %} class="flex-sm-fill text-sm-center nav-link " href="/orders/canceled"><span class="icon"><i class="far fa-times-circle"></i></span>Canceled</a>
                          </nav>
</div>
                        </div>
                      </div>
                    </div>
                  </div>
                </section>
 <section id="table">
                  <div class="container-fluid">
                    <div class="row">
                      <div class="col-md-12">
                        <div class="card card_v2">
                          <div class="card-body">
                            <div class="responsive-table def_table">
                              <div class="table-responsive">
                                <!-- table sections -->
                                <table class="table order_page" id="service-table">
                                  <thead>
                                    <tr>
                                      <th>ID</th>
                                      <th>Date</th>
                                      <th class="width-40">Link</th>
                                      <th>
                                        $ Charge
                                      </th>
                                      <th class="nowrap">Start count</th>
                                      <th>Quantity</th>
                                      <th>Service</th>
                                      <th>Remains</th>
                                      <th>Status</th>
                                      
                                      <th></th>
                                    </tr>
                                  </thead>
                                  <tbody>
                                    <tr>
                             
                                          
                                           {% for order in orders %}
              
<td >{{ order['id'] }}

  <!-- Refill Status -->
  {% if order['refillButton'] %}
    <div class="col-lg-6 col-12">
  {% elseif order['cancelButton'] %}
    <div class="col-lg-6 col-12">
  {% else %}
    <div class="col-lg-8 col-12">
  {% endif %}

  <!-- Order Source -->
  {% if order['order_where'] == "api" %}
    <a class="btn btn-actions">Api</a>
  {% endif %}

  <!-- Copy ID Button -->
  <a 
    class="link-to-copy" 
    onclick="copyToClipboard('{{ order['id'] }}')" 
    data-toggle="tooltip" 
    data-placement="top" 
    title="Click to copy!" 
  >
    Copy ID
  </a>
</td>




                <td class="order-history_date">
                
                                                {{ order['date'] }}
                                            
                </td>
                
                
                <td class="width-40 order-url">
                                                <a href="{{ order['link'] }}" target="_blank" class="order_link">
                                                    {{ order['link'] }}
                                                </a>
                                           </td>
            
            
                 <td>{{ (order['charge'])  }}</td>
                <td class="nowrap">{{ order['start_count'] }}</td>
                <td>{{ order['quantity'] }}</td>
                <td><b>ID {{ order["service_id"] }}</b> -{{ order['service'] }}</td> 
                <td>{{ order['remains'] }}</td>
                
                
                
                <td> {{order['status']}}
								</td>
                
                
      <td>
{% if order["refillButton"] == "2" %}
{% if order['status'] == "Completed"  %}

{% if order['show_refill'] == "true"  %}
<a href="orders/refill/{{order['id']}}" class="btn btn-sm refill-button">Refill</a>
<br><br>
{% endif %}
{% endif %}
{% endif %}
{% if order["refillButton"] == "3" %}

{% if order['status'] == "Completed"  %}

{% if order['show_refill'] == "true"  %}
  <button data-tippy-content="Refill will be available in {{order['refillTimeLeft']}}" class="btn btn-sm refill-button">Refill</button>
{% endif %}
{% endif %}
{% endif %}
{% if order["refillButton"] == "4" %}



{% if order['status'] == "Completed"  %}

{% if order['show_refill'] == "true"  %}
<button type="button" class="btn btn-sm refill-button" disabled="true">{{"Refilling"}}</button>
{% endif %}
{% endif %}
{% endif %}

{% if order['cancelButton']   == true %}
         


                   <a href="orders/cancel/{{order['id']}}" class="btn btn-actions bg-danger">cancel</a>
               {% endif %}

                 </td>
                 
                 
                 
                 
                 
                 
              </tr>
            {% endfor %}

          </tbody>
        </table>
      </div>

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

          {% if pagination["current"] != 1 %}
            <li>
              <a class="btn btn-actions" 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 class="btn btn-actions" 
 href="orders/{{ status }}/{{ page }}{% if search %}?search={{ search }}{% endif %}">{{ page }}</a></li>
            {%endif%}
          {% endfor %}

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

        </ul>
      {% endif %}
      
      </tbody>
                                </table>
                                                            </div>
                    </div>
                   </div>
               </div>
            </div>
        </div>
    </div>
</section>

                </div>
            </div>
        </main>
<script>
  function copyToClipboard(text) {
    // Create a temporary input element
    const tempInput = document.createElement("input");
    tempInput.style.position = "absolute";
    tempInput.style.left = "-9999px";
    tempInput.value = text;
    document.body.appendChild(tempInput);

    // Select the text and copy it
    tempInput.select();
    tempInput.setSelectionRange(0, 99999); // For mobile devices
    document.execCommand("copy");

    // Remove the temporary input
    document.body.removeChild(tempInput);

    // Show a tooltip or alert
    alert("Copied: " + text);
  }
</script>

 {% include 'footer.twig' %}