{% extends "base.html" %}

{% block title %}
{{ _("Welcome") }}
{% endblock %}

{% block description %}
{{ _("Welcome to the best place to find Luanti mods, games, and texture packs") }}
{% endblock %}

{% block scriptextra %}
<script type="application/ld+json">
{
  "@context": "https://schema.org",
  "@type": "WebSite",
  "url": "https://content.luanti.org/",
  "potentialAction": {
    "@type": "SearchAction",
    "target": "https://content.luanti.org/packages?q={search_term_string}",
    "query-input": "required name=search_term_string"
  }
}
</script>
{% if current_user.is_authenticated %}
	<script src="/static/js/quick_review_voting.js?v=2"></script>
{% endif %}
{% endblock %}

{% block content %}
	{% from "macros/packagegridtile.html" import render_pkggrid %}
	<div id="featuredCarousel" class="carousel slide mt-0 mb-5" data-bs-ride="carousel" data-bs-interval="7500">
		<div class="carousel-indicators">
			{% for package in spotlight_pkgs %}
				<button
						data-bs-target="#featuredCarousel"
						data-bs-slide-to="{{ loop.index - 1 }}"
						{% if loop.index == 1 %}class="active" aria-current="true"{% endif %}></button>
			{% endfor %}
		</div>
		<div class="carousel-inner">
			{% for package in spotlight_pkgs %}
				{% set meta = package.get_translated(load_desc=False) %}
				{% set cover_image = package.get_cover_image_url() %}
				{% set tags =  package.tags | sort(attribute="views", reverse=True) %}
				<div class="carousel-item {% if loop.index == 1 %}active{% endif %}">
					<a href="{{ package.get_url('packages.view') }}">
						<div class="ratio ratio-16x9">
							<img src="{{ cover_image }}"
								alt="{{ _('%(title)s by %(author)s', title=meta.title, author=package.author.display_name) }}">
						</div>
						<div class="carousel-caption text-shadow">
							<h3 class="mt-0 mb-3">
								{% if package.author %}
									{{ _('<strong>%(title)s</strong> by %(author)s', title=meta.title, author=package.author.display_name) }}
								{% else %}
									<strong>{{ meta.title }}</strong>
								{% endif %}
							</h3>
							<p>
								{{ meta.short_desc }}
							</p>
							{% if package.author %}
								<div class="d-none d-md-block">
									<span class="me-2">
										{{ package.type.text }}
									</span>
									{% for warning in package.content_warnings %}
										<span class="badge bg-warning" title="{{ warning.description }}">
											<i class="fas fa-exclamation-circle" style="margin-right: 0.3em;"></i>
											{{ warning.title }}
										</span>
									{% endfor %}
									{% for tag in tags[:3] %}
										{% set trans = tag.get_translated() %}
										<span class="badge bg-primary" title="{{ trans.description or '' }}">
											{{ trans.title }}
										</span>
									{% endfor %}
									<span class="btn" title="{{ _('Reviews') }}">
										<i class="fas fa-star-half-alt"></i>
										<span class="count">
											{% set summary = package.get_review_summary() %}
											+{{ summary[0] }} / {{ summary[1] }} / -{{ summary[2] }}
										</span>
									</span>
								</div>
							{% endif %}
						</div>
					</a>
				</div>
			{% endfor %}
		</div>
		<button class="carousel-control-prev" role="button" data-bs-target="#featuredCarousel" data-bs-slide="prev">
			<span class="carousel-control-prev-icon" aria-hidden="true"></span>
			<span class="visually-hidden">{{ _("Previous") }}</span>
		</button>
		<button class="carousel-control-next" role="button" data-bs-target="#featuredCarousel" data-bs-slide="next">
			<span class="carousel-control-next-icon" aria-hidden="true"></span>
			<span class="visually-hidden">{{ _("Next") }}</span>
		</button>
	</div>
	<!-- <div class="text-end mb-5 text-muted" style="opacity: 0.4;">
		<a href="/help/featured/" class="btn">
			<i class="fas fa-question-circle me-1"></i>
			{{ _("Featured") }}
		</a>
	</div> -->

	<h2 class="mb-3">{{ _("Recently Added") }}</h2>
	{{ render_pkggrid(new) }}
	<p class="text-center">
		<a href="{{ url_for('packages.list_all', sort='approved_at', order='desc') }}" class="btn btn-secondary">
			{{ _("See more") }}
			<span class="sr-only">
				{{ _("Recently Added") }}
			</span>
		</a>
	</p>

	<h2 class="mb-3">{{ _("Recently Updated") }}</h2>
	{{ render_pkggrid(updated) }}
	<p class="text-center">
		<a href="{{ url_for('packages.list_all', sort='last_release', order='desc') }}" class="btn btn-secondary">
			{{ _("See more") }}
			<span class="sr-only">
				{{ _("Recently Updated") }}
			</span>
		</a>
	</p>

	<h2 class="mb-3">{{ _("Top Games") }}</h2>
	{{ render_pkggrid(pop_gam) }}
	<p class="text-center">
		<a href="{{ url_for('packages.list_all', type='game', sort='score', order='desc') }}" class="btn btn-secondary">
			{{ _("See more") }}
			<span class="sr-only">
				{{ _("Top Games") }}
			</span>
		</a>
	</p>

	<h2 class="mb-3">{{ _("Top Mods") }}</h2>
	{{ render_pkggrid(pop_mod) }}
	<p class="text-center">
		<a href="{{ url_for('packages.list_all', type='mod', sort='score', order='desc') }}" class="btn btn-secondary">
			{{ _("See more") }}
			<span class="sr-only">
				{{ _("Top Mods") }}
			</span>
		</a>
	</p>

	<h2 class="mb-3">{{ _("Top Texture Packs") }}</h2>
	{{ render_pkggrid(pop_txp) }}
	<p class="text-center">
		<a href="{{ url_for('packages.list_all', type='txp', sort='score', order='desc') }}" class="btn btn-secondary">
			{{ _("See more") }}
			<span class="sr-only">
				{{ _("Top Texture Packs") }}
			</span>
		</a>
	</p>


	<h2 class="mb-3">{{ _("Search by Tags") }}</h2>
	{% for pair in tags %}
		{% set count = pair[0] %}
		{% set tag = pair[1] %}

		<a class="btn btn-sm btn-secondary m-1" rel="nofollow"
				title="{{ tag.get_translated().description or '' }}"
				href="{{ url_for('packages.list_all', tag=tag.name) }}">
			{{ tag.get_translated().title }}
			<span class="badge rounded-pill bg-light text-dark ms-1">{{ count }}</span>
		</a>
	{% endfor %}


	<h2 class="mb-3">{{ _("Highest Reviewed") }}</h2>
	{{ render_pkggrid(high_reviewed) }}
	<p class="text-center">
		<a href="{{ url_for('packages.list_all', sort='reviews', order='desc') }}" class="btn btn-secondary">
			{{ _("See more") }}
			<span class="sr-only">
				{{ _("Highest Reviewed") }}
			</span>
		</a>
	</p>

	<div class="clearfix"></div>

	<a href="{{ url_for('packages.list_reviews') }}" class="btn btn-secondary float-end">
		{{ _("All reviews") }}
	</a>
	<h2 class="my-3">{{ _("Recent Positive Reviews") }}</h2>
	{% from "macros/reviews.html" import render_reviews with context %}
	{{ render_reviews(reviews, current_user, True) }}


	<div class="text-center mt-5">
		<small>
			{{ _("CDB has %(count)d packages, with a total of %(downloads)d downloads.", count=count, downloads=downloads) }}
		</small>
	</div>
<!-- </main> -->
{% endblock %}
