{% extends "abstracts/base.jinja" %}
{% block title %}Maloja - {{ info.track.title }}{% endblock %}

{% import 'snippets/links.jinja' as links %}

{% block scripts %}
	<script src="/rangeselect.js"></script>
	<script>
		function scrobble(encodedtrack) {
			neo.xhttprequest('/apis/mlj_1/newscrobble?nofix&' + encodedtrack,data={},method="POST").then(response=>{window.location.reload()});
		}
	</script>
{% endblock %}

{% set track = filterkeys.track %}
{% set info = dbc.track_info({'track':track}) %}

{% set initialrange ='month' %}


{% set encodedtrack = mlj_uri.uriencode({'track':track}) %}


{% block content %}


{% import 'partials/awards_track.jinja' as awards %}


<table class="top_info">
	<tr>
		<td class="image">
			{% if adminmode %}
			<div
				class="changeable-image" data-uploader="b64=>upload('{{ encodedtrack }}',b64)"
				style="background-image:url('{{ images.get_track_image(track) }}');"
			></div>
			{% else %}
			<div style="background-image:url('{{ images.get_track_image(track) }}');">
			</div>
			{% endif %}
		</td>
		<td class="text">
			<span>{{ links.links(track.artists) }}</span><br/>
			<h1 class="headerwithextra">{{ info.track.title }}</h1>
				{{ awards.certs(track) }}
				<span class="rank"><a href="/charts_tracks?max=100">#{{ info.position }}</a></span>
				<br/>

			<p class="stats">
				{% if adminmode %}<button type="button" onclick="scrobble('{{ encodedtrack }}')">Scrobble now</button>{% endif %}
				<a href="{{ mlj_uri.create_uri("/scrobbles",filterkeys) }}">{{ info['scrobbles'] }} Scrobbles</a>
			</p>





			{{ awards.medals(info) }}
			{{ awards.topweeks(info) }}


		</td>
	</tr>
</table>


<table class="twopart">

	<tr>
		<td>
			<h2 class="headerwithextra"><a href='{{ mlj_uri.create_uri("/pulse",filterkeys) }}'>Pulse</a></h2>
			<br/>
			{% for r in xranges %}
			<span
				onclick="showRangeManual('pulse','{{ r.identifier }}')"
				class="stat_selector_pulse selector_pulse_{{ r.identifier }}"
				style="{{ 'opacity:0.5;' if initialrange==r.identifier else '' }}">
				{{ r.localisation }}
			</span>
			{% if not loop.last %}|{% endif %}
			{% endfor %}

      		<br/><br/>

			{% for r in xranges %}

			<span
				class="stat_module_pulse pulse_{{ r.identifier }}"
				style="{{ 'display:none;' if initialrange!=r.identifier else '' }}"
				>

			{% with limitkeys={"since":r.firstrange},delimitkeys={'step':r.identifier,'trail':1} %}
			{% include 'partials/pulse.jinja' %}
			{% endwith %}
			</span>

			{% endfor %}
		</td>
		<td>
			<!-- We use the same classes / function calls here because we want it to switch together with pulse -->
			<h2 class="headerwithextra"><a href='{{ mlj_uri.create_uri("/performance",filterkeys) }}'>Performance</a></h2>
			<br/>
			{% for r in xranges %}
				<span
					onclick="showRangeManual('pulse','{{ r.identifier }}')"
					class="stat_selector_pulse selector_pulse_{{ r.identifier }}"
					style="{{ 'opacity:0.5;' if initialrange==r.identifier else '' }}">
					{{ r.localisation }}
				</span>
				{% if not loop.last %}|{% endif %}
			{% endfor %}

      		<br/><br/>

			{% for r in xranges %}

			<span
				class="stat_module_pulse pulse_{{ r.identifier }}"
				style="{{ 'display:none;' if initialrange!=r.identifier else '' }}"
				>

			{% with limitkeys={"since":r.firstrange},delimitkeys={'step':r.identifier,'trail':1} %}
			{% include 'partials/performance.jinja' %}
			{% endwith %}
			</span>

			{% endfor %}

		</td>
	</tr>
</table>


<h2><a href='{{ mlj_uri.create_uri("/scrobbles",filterkeys) }}'>Last Scrobbles</a></h2>

{% with amountkeys = {"perpage":15,"page":0} %}
{% include 'partials/scrobbles.jinja' %}
{% endwith %}


{% endblock %}
