{% extends "todo/todo_base.html" %}

{% block title %}
	{{ _("Editor Work Queue") }}
{% endblock %}

{% block content %}
	{% if reports %}
		<h2 class="mb-4">{{ _("Reports") }}</h2>
		<nav class="list-group">
			{% for report in reports %}
				<a class="list-group-item list-group-item-action" href="{{ url_for('report.view',  rid=report.id) }}">
					<div class="row">
						<div class="col">
							<span class="badge bg-secondary me-3">{{ report.category.title }}</span>
							{{ report.title }}
							{% if report.user %}
								by {{ report.user.display_name }}
							{% endif %}
						</div>
						<div class="col-auto">
							{{ report.created_at | timedelta }} ago
						</div>
					</div>
				</a>
			{% endfor %}
		</nav>
	{% endif %}

	<h2 class="mb-4">{{ _("Approval Queue") }}</h2>
	{% if can_approve_scn and screenshots %}
		<div class="card my-4">
			<h3 class="card-header">{{ _("Screenshots") }}
				<form class="float-end"  method="post" action="{{ url_for('todo.view_editor') }}">
					<input type="hidden" name="csrf_token" value="{{ csrf_token() }}" />
					<input type="hidden" name="action" value="screenshots_approve_all" />
					<input class="btn btn-sm btn-primary" type="submit" value="{{ _('Approve All') }}" />
				</form>
			</h3>
			<ul class="card-body d-flex p-0 flex-row flex-wrap justify-content-start align-content-start p-4">
				{% for s in screenshots %}
					<li class="packagetile flex-fill"><a href="{{ s.get_edit_url() }}"
						style="background-image: url({{ s.get_thumb_url(3) }});">
						<div class="packagegridscrub"></div>
						<div class="packagegridinfo">
							<h3>
								{{ s.title }}
								<br />
								<small>{{ s.package.title }} by {{ s.package.author.display_name }}</small>
							</h3>
							<p></p>
						</div>
					</a></li>
				{% else %}
					<li><i>{{ _("No screenshots need approval.") }}</i></li>
				{% endfor %}
				{% for i in range(4) %}
					<li class="packagetile flex-fill"></li>
				{% endfor %}
			</ul>
		</div>
	{% endif %}

	<div class="row">
		{% if can_approve_new and (packages or wip_packages) %}
		<div class="col-sm-6">
			<div class="card">
				<h3 class="card-header">{{ _("Packages") }}</h3>
				<div class="list-group list-group-flush">
					{% for p in packages %}
						<a href="{{ p.get_url('packages.view') }}" class="list-group-item list-group-item-action">
							<span class="float-end" title="Created {{ p.created_at | full_datetime }}">
								<small>
									{{ p.created_at | timedelta }} ago
								</small>
							</span>

							{% if "Other" in p.license.name or "Other" in p.media_license.name %}
								<span class="me-2 badge bg-info">License</span>
							{% else %}
								<span class="me-2 badge bg-success">Ready</span>
							{% endif %}

							{{ p.title }} by {{ p.author.display_name }}
						</a>
					{% else %}
						<li class="list-group-item"><i>{{ _("No packages need approval.") }}</i></li>
					{% endfor %}
				</div>
			</div>
		</div>
		{% endif %}

		{% if can_approve_rel and releases %}
		<div class="col-sm-6">
			<div class="card">
				<h3 class="card-header">{{ _("Releases") }}</h3>
				<ul class="list-group list-group-flush" style="max-height: 500px; overflow: hidden auto;">
					{% for r in releases %}
						<li class="list-group-item">
							{% if r.task_id %}
								<span class="me-2 badge bg-warning">{{ _("Importing") }}</span>
							{% endif %}
							<a href="{{ r.get_edit_url() }}">{{ r.title }}</a>
							on
							<a href="{{ r.package.get_url('packages.view') }}">
								{{ _("%(title)s by %(display_name)s",
										title=r.package.title, display_name=r.package.author.display_name) }}
							</a>
						</li>
					{% else %}
						<li class="list-group-item"><i>{{ _("No releases need approval.") }}</i></li>
					{% endfor %}
				</ul>
			</div>
		</div>
		{% endif %}
	</div>

	{% if not (packages or screenshots or releases) %}
		<p>
			<i>{{ _("All done!") }}</i>
		</p>
	{% endif %}

	{% if license_needed %}
		<h2 class="mt-5">{{ _("License Needed") }}</h2>
		<div class="card">
			<h3 class="card-header">{{ _("License Needed") }}</h3>
			<div class="list-group list-group-flush">
				{% for p in license_needed %}
					<a href="{{ p.get_url('packages.view') }}" class="list-group-item list-group-item-action">
						<span class="float-end" title="Created {{ p.created_at | full_datetime }}">
							<small>
								{{ p.created_at | timedelta }} ago
							</small>
						</span>

						<span class="me-2 badge bg-{{ p.state.color }}">{{ p.state.value }}</span>

						{{ p.title }} by {{ p.author.display_name }}
					</a>
				{% endfor %}
			</div>
		</div>
	{% endif %}

	{% if total_to_tag != 0 %}
		<h2 class="mt-5">{{ _("Tag Packages") }}</h2>

		<p>
			{{ _("%(total_to_tag)d / %(total_packages)d packages don't have any tags.",
					total_to_tag=total_to_tag, total_packages=total_packages) }}
		</p>

		<div class="progress my-4">
			{% set perc = 100 * (total_packages - total_to_tag) / total_packages %}
			<div class="progress-bar bg-success" role="progressbar"
				style="width: {{ perc }}%" aria-valuenow="{{ perc }}" aria-valuemin="0" aria-valuemax="100"></div>
		</div>

		<a class="btn btn-primary" href="{{ url_for('todo.tags') }}">{{ _("View Tags") }}</a>
	{% endif %}

	{% if unfulfilled_meta_packages %}
		<h2 class="mt-5">
			<span class="fas fa-exclamation-triangle pe-2" style="color: orange;"></span>
			{{ unfulfilled_meta_packages }}
			{{ _("Unfulfilled Dependencies") }}
		</h2>

		<p>
			{{ _("Mod names that have hard dependers, but no packages providing them.") }}
		</p>

		<a class="btn btn-primary" href="{{ url_for('todo.modnames') }}">
			{{ _("View") }}
		</a>
	{% endif %}


	<h2 class="mt-5">{{ _("WIP") }}</h2>

	{% if can_approve_new and (packages or wip_packages) %}
		<div class="card">
			<h3 class="card-header">WIP Packages</h3>
			<div class="list-group list-group-flush" style="max-height: 300px; overflow: hidden auto;">
				{% for p in wip_packages %}
					<a href="{{ p.get_url('packages.view') }}" class="list-group-item list-group-item-action">
						<span class="float-end" title="Created {{ p.created_at | full_datetime }}">
							<small>
								{{ p.created_at | timedelta }} ago
							</small>
						</span>

						{% if p.state == p.state.WIP %}
							<span class="me-2 badge bg-warning">{{ _("WIP") }}</span>
						{% else %}
							<span class="me-2 badge bg-danger">{{ p.state.value }}</span>
						{% endif %}

						{{ p.title }} by {{ p.author.display_name }}
					</a>
				{% else %}
					<li class="list-group-item"><i>{{ _("No packages need approval.") }}</i></li>
				{% endfor %}
			</div>
		</div>
	{% endif %}


	<div class="mt-5"></div>
	{% if current_user.rank.at_least(current_user.rank.MODERATOR) %}
		<a class="btn btn-secondary float-end" href="{{ url_for('admin.audit') }}">
			{{ _("View All") }}
		</a>
	{% endif %}
	<h2>{{ _("Recent Actions") }}</h2>

	{% from "macros/audit_log.html" import render_audit_log %}
	{{ render_audit_log(audit_log, current_user) }}

{% endblock %}
