{% extends "home.html" %}
{%- import 'component/sorting_time.html' as sorting_time -%}

{% block pagetype %}search{% endblock %}

{% block title %}
<title>Search for "{{query}}" - {{SITE_TITLE}}"</title> <meta name="description" content="{{total}} result{{'s' if total != 1 else ''}}">
{% endblock %}

{% block navbar %}
	{% if not '/users/' in request.path %}
		<div class="mt-5 d-flex align-items-center">
			<div class="dropdown dropdown-actions">
				<button class="btn btn-secondary dropdown-toggle" role="button" id="dropdownMenuButton" data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
					{% if t=="hour" %}<i class="fas fa-clock mr-1"></i>
					{% elif t=="day" %}<i class="fas fa-calendar-day mr-1"></i>
					{% elif t=="week" %}<i class="fas fa-calendar-week mr-1"></i>
					{% elif t=="month" %}<i class="fas fa-calendar-alt mr-1"></i>
					{% elif t=="year" %}<i class="fas fa-calendar mr-1"></i>
					{% elif t=="all" %}<i class="fas fa-infinity mr-1"></i>
					{% endif %}
				{{t | capitalize}}
				</button>
				<div class="dropdown-menu" aria-labelledby="dropdownMenuButton" x-placement="bottom-start" style="position: absolute; will-change: transform; top: 0px; left: 0px; transform: translate3d(0px, 31px, 0px);">
					{% if t != "hour" %}<a class="dropdown-item" href="?q={{query | urlencode}}&sort={{sort}}&t=hour"><i class="fas fa-clock mr-2"></i>Hour</a>{% endif %}
					{% if t != "day" %}<a class="dropdown-item" href="?q={{query | urlencode}}&sort={{sort}}&t=day"><i class="fas fa-calendar-day mr-2"></i>Day</a>{% endif %}
					{% if t != "week" %}<a class="dropdown-item" href="?q={{query | urlencode}}&sort={{sort}}&t=week"><i class="fas fa-calendar-week mr-2"></i>Week</a>{% endif %}
					{% if t != "month" %}<a class="dropdown-item" href="?q={{query | urlencode}}&sort={{sort}}&t=month"><i class="fas fa-calendar-alt mr-2"></i>Month</a>{% endif %}
					{% if t != "year" %}<a class="dropdown-item" href="?q={{query | urlencode}}&sort={{sort}}&t=year"><i class="fas fa-calendar mr-2"></i>Year</a>{% endif %}
					{% if t != "all" %}<a class="dropdown-item" href="?q={{query | urlencode}}&sort={{sort}}&t=all"><i class="fas fa-infinity mr-2"></i>All</a>{% endif %}
				</div>
			</div>
			{% set query_text = 'q=' ~ query | urlencode %}
			{{sorting_time.sort_dropdown(sort, t, SORTS_POSTS, query_text)}}
		</div>
	{% endif %}
{% endblock %}
{% block content %}
<div class="row no-gutters my-md-3">
	<div class="col">
		<div class="card search-results">
			<div class="card-header bg-white d-none">
				<ul class="list-inline no-bullets mb-0">
					<li class="list-inline-item active mr-4"><i class="fas fa-align-left text-gray-400"></i></li>
					<li class="list-inline-item"><i class="fas fa-link text-gray-400"></i></li>
				</ul>
			</div>
			<div class="card-body">
				<div class="pl-md-3">
					<div class="text-muted text-small mb-1">Advanced search parameters (with examples): "author:quadnarca", "domain:reddit.com", "over18:true"<div>
					<br>
					<div class="text-muted text-small mb-1">Showing {% block listinglength %}{{listing | length}}{% endblock %} of {{total}} result{{'s' if total != 1 else ''}} for</div>
					<h1 class="h4 mb-0">{{query}}</h1>
				</div>
			</div>
		</div>
	</div>
</div>
<div class="row no-gutters">
	<div class="col">
		<div class="flex-row box-shadow-bottom d-flex justify-content-center justify-content-md-between align-items-center">
			<ul class="nav settings-nav">
				<li class="nav-item">
					<a class="nav-link{% if '/comments/' in request.path %} active{% endif %}" href="/search/comments/?sort={{sort}}&q={{query | urlencode}}&t={{t}}">Comments</a>
				</li>
				<li class="nav-item">
					<a class="nav-link{% if '/posts/' in request.path %} active{% endif %}" href="/search/posts/?sort={{sort}}&q={{query | urlencode}}&t={{t}}">Posts</a>
				</li>
				<li class="nav-item">
					<a class="nav-link{% if '/users/' in request.path %} active{% endif %}" href="/search/users/?sort={{sort}}&q={{query | urlencode}}&t={{t}}">Users</a>
				</li>
			</ul>
		</div>
	</div>
</div>
<div class="row no-gutters">
	<div class="col-12">
		<div class="posts" id="posts">
			{% block listing_template %}
				{% include "submission_listing.html" %}
			{% endblock %}
		</div>
	</div>
</div>
{% endblock %}
{% block pagenav %}
<nav aria-label="Page navigation">
	<ul class="pagination pagination-sm mb-0">
		<li class="page-item{% if page==1 %} disabled{% endif %}">
			<small><a class="page-link" href="?sort={{sort}}&q={{query | urlencode}}&t={{t}}&page={{page-1}}" tabindex="-1"{% if page==1 %} aria-disabled="true"{% endif %}>Back</a></small>
		</li>
		<li class="page-item{% if not next_exists %} disabled{% endif %}">
			<small><a class="page-link" href="?sort={{sort}}&q={{query | urlencode}}&t={{t}}&page={{page+1}}">Next</a></small>
		</li>
	</ul>
</nav>
{% endblock %}
