{% extends "default.html" %}

{% block title %}
<title>{{SITE_TITLE}}</title>

{% endblock %}

{% block content %}
<h2 class="mt-2">Admin Tools</h2>

{% if g.loggedin_counter is not none and g.loggedout_counter is not none %}
<div class="mb-3">
	<strong>Users Here Now:</strong> {{g.loggedin_counter + g.loggedout_counter}} &mdash;
	<a href="/admin/loggedin">{{g.loggedin_counter}} Logged-In</a> |
	<a href="/admin/loggedout">{{g.loggedout_counter}} Logged-Out</a>
</div>
{% else %}
<div class="mb-3">
	<strong>Users Here Now:</strong> (tracking disabled)
</div>
{% endif %}

<h3>Content</h3>
<ul>
	<li><a href="/admin/image_posts">Image Posts</a></li>
	<li><a href="/admin/reported/comments">Reported Comments/Posts</a></li>
	<li><a href="/admin/removed/comments">Removed Comments/Posts</a></li>
</ul>

<h3>Filtering</h3>
<ul>
	<li><a href="/admin/filtered/comments">Filtered Comments/Posts</a></li>
</ul>

<h3>Users</h3>
<ul>
	<li><a href="/admin/users">Users Feed</a></li>
	<li><a href="/admin/shadowbanned">Shadowbanned Users</a></li>
	<li><a href="/banned">Permabanned Users</a></li>
</ul>

<h3>Safety</h3>
<ul>
	<li><a href="/admin/banned_domains">Banned Domains</a></li>
	<li><a href="/admin/alt_votes">Multi Vote Analysis</a></li>
</ul>

<h3>Grant</h3>
<ul>
	<li><a href="/admin/badge_grant">Grant Badges</a></li>
	<li><a href="/admin/badge_remove">Remove Badges</a></li>
</ul>

<h3>API Access Control</h3>
<ul>
	<li><a href="/admin/apps">Apps</a></li>
</ul>

<h3>Statistics</h3>
<ul>
	<li><a href="/stats">Content Stats</a></li>
	<li><a href="/weekly_chart">Weekly Stat Chart</a></li>
	<li><a href="/daily_chart">Daily Stat Chart</a></li>
</ul>

<section id="admin-section-scheduler" class="admin-section mt-3">
	<h3>Scheduler</h3>
	<ul>
		{%- if v.admin_level >= PERMS['SCHEDULER'] -%}<li><a href="/tasks/">Tasks</a></li>{%- endif -%}
		{%- if v.admin_level >= PERMS['SCHEDULER_POSTS'] -%}<li><a href="/tasks/scheduled_posts">Scheduled Posts</a></li>{%- endif -%}
	</ul>
</section>

{% if v.admin_level >= 3 %}
<section id="admin-section-performance" class="admin-section mt-3">
	<h3>Performance</h3>
	<ul>
		<li><a href="/performance/">Performance</a></li>
	</ul>
</section>
{% endif %}

{% if v.admin_level >= 3 %}
	<h3>Site Settings</h3>
	{%- macro site_setting_bool(name, label) -%}
		<div class="custom-control custom-switch">
			<input autocomplete="off" type="checkbox" class="custom-control-input" id="site-setting-{{name}}" {% if site_settings[name] %}checked{% endif %} onchange="postToastSimple(this,'/admin/site_settings/{{name}}');">
			<label class="custom-control-label" for="site-setting-{{name}}">{{label}}</label>
		</div>
	{%- endmacro -%}
	{%- macro site_setting_int(name, label) -%}
		<div class="custom-control custom-switch">
			<input type="number" class="" id="site-setting-{{name}}" name="{{name}}" value="{{ site_settings[name] }}" 
				onblur="postToastSimple(null, '/admin/site_settings/{{name}}', 'POST', { new_value: this.value })"/>
			<label for="site-setting-{{name}}">{{label}}</label>
		</div>
	{%- endmacro -%}
	{{site_setting_bool('signups', 'Signups')}}
	{{site_setting_bool('bots', 'Bots')}}
	{{site_setting_bool('FilterNewPosts', 'Filter New Posts')}}
	{{site_setting_bool('Read-only mode', 'Read-Only Mode')}}
	<div class="custom-control custom-switch">
		<input autocomplete="off" type="checkbox" class="custom-control-input" id="under_attack" name="under_attack" {% if under_attack%}checked{% endif %} onchange="postToastSimple(this,'/admin/under_attack');">
		<label class="custom-control-label" for="under_attack">Under attack mode</label>
	</div>

	<h4>Comment Filtering</h4>
	{{site_setting_int('FilterCommentsMinComments', 'Minimum Comments')}}
	{{site_setting_int('FilterCommentsMinKarma', 'Minimum Karma')}}
	{{site_setting_int('FilterCommentsMinAgeDays', 'Minimum Account Age (Days)')}}

	<h4>Private Mode Requirements</h4>
	{{site_setting_int('min_comments_private_profile', 'Minimum Comments')}}
	{{site_setting_int('min_truescore_private_profile', 'Minimum Karma')}}
	{{site_setting_int('min_age_days_private_profile', 'Minimum Account Age (Days)')}}

	<button class="btn btn-primary mt-3" onclick="postToastSimple(this,'/admin/purge_cache');">PURGE CDN CACHE</button>
	<button class="btn btn-primary mt-3" onclick="postToastSimple(this,'/admin/dump_cache');">DUMP INTERNAL CACHE</button>
{% endif %}
{% if g.debug %}
<section id="admin-section-debug" class="admin-section mt-3">
	<h4>Debug Options</h4>
	{% if v.admin_level >= PERMS["DEBUG_LOGIN_TO_OTHERS"] %}
	<div class="login-to-others mt-3">
		<h5>Login to another's account</h5>
		<form action="/dev/sessions/" method="post">
			<input type="hidden" name="formkey", value="{{v.formkey}}">
			<label for="username">Username</label>
			<input name="username" required>
			<button type="submit" class="btn btn-primary">Login</button>
		</form>
	</div>
	{% endif %}
</section>
{% endif %}
{% endblock %}
