{% include 'header.twig' %}


{% if contentText is not empty %}
	<div class="container">
		<div class="row">
			<div class="col-md-8 col-md-offset-2">
				<div class="well ">
					{{ contentText }}
				</div>
			</div>
		</div>
	</div>
{% endif %}

<div class="container-fluid">
	<div class="row">
		<div class="col-lg-12">
			<ul class="nav nav-pills ">
				<li class="pull-right search">
					<form action="" method="get">
						<div class="input-group">
							<input type="text" name="search" class="form-control" value="{{ search }}" placeholder="Search Refill">
							<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>
				</li>
			</ul>
			<div class="well well-float">
				<table class="table ">
					<thead>
						<tr>
							<th>{{lang["refill.table.id"]}}</th>
							<th>{{lang["refill.table.order"]}}</th>
							<th>{{lang["refill.table.link"]}}</th>
							<th>{{lang["refill.table.start.count"]}}</th>
							<th>{{lang["refill.table.quantity"]}}</th>
							<th>{{lang["refill.table.date"]}}</th>
							<th>{{lang["refill.table.status"]}}</th>
						</tr>

					</thead>
					<tbody>
						{% for order in orders %}
							<tr>
								<td>
									{{ order['task_id'] }}
								</td>

								<td>
									<a href="{{site['url']}}/orders/?search={{order['order_id']}}">{{ order['order_id'] }}</a>
								</td>
								<td>
									<a target="_blank" href="{{ order['order_link'] }}">{{ order['order_link'] }}</a>
								</td>

								<td>{{ order['order_start'] }}</td>
								<td>{{ order['order_quantity'] }}</td>
								<td><td>{{ show_date(order['createdAtFormatted']) }}</td></td>
								<td>
									<div style="line-height:{% if order['task_status'] == "inprogress" %} 1 {% endif %}; cursor:pointer; padding:3px 5px;  text-align:center; border-radius:20px; color:white; background:#{% if order['task_status'] == "completed"  %}0e7f00 {% elseif order['task_status'] == "inprogress" %}260bc1  {% elseif order['task_status'] == "pending" %}42b7af {% elseif order['task_status'] == "error" %}42b7af  {% else %}f25800 {% endif %} ;">{{ order['task_status']|capitalize  }}</div>
								</td>

							</tr>
						{% endfor %}
					</tbody>
				</table>
			</div>
			{% if pagination["count"] > 1 %}
				<ul class="pagination">

					{% if pagination["current"] == 1 %}
						<li>
							<a href="refill/{{ 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) %}
							<div style="border:1px solid rgb(128,128,128); padding:4px; margin-left:8px; min-width:21px; text-align:center;">
								<li {% if page == pagination['current'] %} class="active" {%endif%}>
									<a href="refill/{{ status }}/{{ page }}{% if search %}?search={{ search }}{% endif %}">{{ page }}</a>
								</li>
							</div>
							{%endif%}
						{% endfor %}

						{% if pagination['current'] < pagination['count'] %}
							<li>
								<a style="margin-left:8px;" href="refill/{{ 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' %}
