{% extends "packages/package_base.html" %}

{% block title %}
{{ _("Supported Games") }}
{% endblock %}

{% block content %}
	<a class="float-end btn btn-secondary" href="{{ url_for('flatpage', path='help/game_support') }}">
		{{ _("Documentation") }}
	</a>
	<h2 class="mt-0">{{ self.title() }}</h2>
	<p>
		{{ _("Game support is configured using the package's .conf file. See the documentation for more info") }}
	</p>

	<div class="list-group">
		<div class="list-group-item">
			<div class="row">
				<span class="col-5">
					{{ _("Package") }}
				</span>
				<span class="col-5">
					{{ _("Source") }}
				</span>
				<span class="col-2 text-end">
					{{ _("Supported?") }}
				</span>
			</div>
		</div>

		{% if package.supports_all_games %}
			<div class="list-group-item">
				{{ _("Supports all games (unless excluded by unsupported_games)") }}
			</div>
		{% endif %}

		{% for support in package.get_sorted_game_support() %}
			<a class="list-group-item list-group-item-action"
					href="{{ support.game.get_url('packages.view') }}">
				<div class="row">
					<span class="col-5">
						{{ _("%(title)s by %(display_name)s",
								title=support.game.title, display_name=support.game.author.display_name) }}
					</span>
					<span class="col-5">
						{% if support.confidence == 1 %}
							{{ _("Detected from dependencies") }}
						{% elif support.confidence == 11 %}
							{{ _("Overridden on ContentDB") }}
						{% elif support.confidence == 10 %}
							{{ package.get_conf_file_name() }}
						{% else %}
							{{ support.confidence }}
						{% endif %}
					</span>
					<span class="col-2 text-end">
						{% if support.supports %}
							<span class="badge bg-success">Yes</span>
						{% else %}
							<span class="badge bg-danger">No</span>
						{% endif %}
					</span>
				</div>
			</a>
		{% else %}
			{% if not package.supports_all_games %}
				<div class="list-group-item text-danger">
					{{ _("Unknown. Please either add supported games or check 'Supports all games'") }}
				</div>
			{% endif %}
		{% endfor %}
	</div>

	{% if mod_conf_lines %}
		<h3>{{ _("Generated %(conf)s lines", conf=package.get_conf_file_name()) }}</h3>
		<pre><code>{{ mod_conf_lines }}</code></pre>
	{% endif %}

	{% if form %}
		<h2>Options</h2>

		{% from "macros/forms.html" import render_field, render_checkbox_field, render_submit_field %}
		<form method="POST" action="" class="tableform">
			{{ form.hidden_tag() }}

			{{ render_checkbox_field(form.enable_support_detection, disabled=force_game_detection) }}
			{% if force_game_detection %}
				<p class="text-muted">
					{{ _("You need to manually define at least one supported game before you can turn this off.") }}
				</p>
			{% endif %}

			{{ render_checkbox_field(form.supports_all_games, disabled=not can_support_all_games) }}
			{% if can_support_all_games %}
				<p class="text-muted">
					{{ _("When checked, this indicates that this package should support all games, unless excluded by unsupported_games.") }}
					{{ _("You can check this and still specify games in supported_games that you've tested.") }}
				</p>
			{% elif package.type.name == "TXP" %}
				<p class="text-muted">
					{{ _("It's not possible for texture packs to support all games.") }}
				</p>
			{% elif package.type.name == "MOD" %}
				<p class="text-muted">
					{{ _("The package depends on a game-specific mod, and so cannot support all games.") }}
				</p>
			{% endif %}

			{% if form.supported and form.unsupported %}
				<h3>
					{{ _("Overrides") }}
				</h3>
				<p class="text-muted">
					{{ _("It's best to add supported/unsupported games to %(conf)s, but in the meantime you can add them here.",
							conf=package.get_conf_file_name()) }}
					{{ _("Adding to %(conf)s allows users who install outside ContentDB to benefit as well.",
							conf=package.get_conf_file_name()) }}
				</p>
				{{ render_field(form.supported, hint=_("Comma-separated game names, ex: minetest_game, nodecore")) }}
				{{ render_field(form.unsupported, hint=_("Comma-separated game names, ex: minetest_game, nodecore")) }}
			{% endif %}

			{{ render_submit_field(form.submit, class_="mt-4 btn btn-primary") }}
		</form>
	{% endif %}
{% endblock %}
