{% extends "base.html" %}

{% block title %}
	{{ collection.title }}
{% endblock %}

{% block description -%}
	{{ collection.short_description }}
{%- endblock %}

{% block headextra %}
	{% set thumb_url = collection.packages and collection.packages[0].get_thumb_url(3, True, "png") %}
	{% if thumb_url -%}
		<meta name="og:image" content="{{ thumb_url }}">
	{%- endif %}
{% endblock %}

{% block author_link -%}
	<a href="{{ url_for('users.profile', username=collection.author.username) }}">
		{{ collection.author.display_name }}
	</a>
{%- endblock %}

{% block content %}
	<div class="float-end">
		<a class="btn btn-secondary" href="{{ url_for('collections.list_all', author=collection.author.username) }}">
			{{ _("%(author)s's collections", author=collection.author.display_name) }}
		</a>
		{% if current_user.is_authenticated %}
			<form method="POST" action="{{ collection.get_url('collections.clone') }}" class="d-inline-block ms-2">
				<input type="hidden" name="csrf_token" value="{{ csrf_token() }}" />
				<button type="submit" class="btn btn-secondary">
					{{ _("Make a copy") }}
				</button>
			</form>
		{% endif %}
		{% if collection.check_perm(current_user, "EDIT_COLLECTION") %}
			<a class="btn btn-danger ms-2" href="{{ collection.get_url('collections.delete') }}">
				{{ _("Delete") }}
			</a>
			<a class="btn btn-primary ms-2" href="{{ collection.get_url('collections.create_edit') }}">
				{{ _("Edit") }}
			</a>
		{% endif %}
	</div>
	<h1>{{ self.title() }}</h1>
	<p class="text-muted">
		{% if collection.private %}
			<span class="badge bg-secondary me-1">
				<i class="fas fa-lock me-1" style="color:#ffac33;"></i>
				{{  _("Private") }}
			</span>
		{% endif %}
		{{ _("A collection by %(author)s", author=self.author_link()) }}
	</p>
	<p class="lead mb-5">
		{{ collection.short_description }}
	</p>
	{% if collection.long_description %}
		<div class="markdown mb-5">
			{{ collection.long_description | markdown }}
		</div>
	{% endif %}

	<section class="mt-5">
		<h2 class="visually-hidden">{{ _("Packages") }}</h2>
		{% if not items %}
			<p class="text-muted">
				{{ _("To add a package, go to the package's page and click 'Add to collection'") }}
			</p>
		{% endif %}
		<div class="grid-2 gap-3">
			{% for item in items %}
				{% set package_link %}
					<a href="{{ item.package.get_url('packages.view') }}">
						{{ item.package.title }}
					</a>
				{% endset %}
				<div>
					<article class="card">
						<div class="ratio ratio-16x9">
							<img loading="lazy" class="card-img-top object-fit-cover" src="{{ item.package.get_thumb_or_placeholder(4) }}" alt="{{ item.package.title }} screenshot">
						</div>
						<div class="card-body">
							{% if item.package.state.name != "APPROVED" %}
								<span class="badge bg-warning float-end">
									{{ item.package.state.value }}
								</span>
							{% endif %}
							<h5 class="mt-0">
								{{ _("%(title)s by %(author)s", title=package_link, author=item.package.author.display_name) }}
							</h5>
							<p class="card-text">
								{% if item.description  %}
									{{ item.description }}
								{% else %}
									{{ item.description or item.package.short_desc }}
								{% endif %}
							</p>
						</div>
					</article>
				</div>
			{% endfor %}
		</div>
	</section>
{% endblock %}
