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

{% import 'snippets/links.jinja' as links %}
{% import 'partials/awards_artist.jinja' as awards %}

{% block scripts %}
	<script src="/statselect.js"></script>
{% endblock %}

{% set artist = filterkeys.artist %}
{% set info = db.artist_info(artist=artist) %}

{% set credited = info.get('replace') %}
{% set included = info.get('associated') %}
{% set initialrange ='month' %}


{% if credited is not none %}
	{% set competes = false %}
{% else %}
	{% set credited = artist %}
	{% set competes = true %}
{% endif %}


{% set encodedartist = mlj_uri.uriencode({'artist':artist}) %}

{% block icon_bar %}
	{% if adminmode %}
		{% include 'icons/edit.jinja' %}

		<div class="iconsubset mergeicons" data-entity_type="artist" data-entity_id="{{ info.id }}" data-entity_name="{{ info.artist }}">
		{% include 'icons/merge.jinja' %}
		{% include 'icons/merge_mark.jinja' %}
		{% include 'icons/merge_unmark.jinja' %}
		{% include 'icons/merge_cancel.jinja' %}
		</div>

		<div class="iconsubset associateicons" data-entity_type="artist" data-entity_id="{{ info.id }}" data-entity_name="{{ info.artist }}">
		{% include 'icons/add_artist.jinja' %}
		{% include 'icons/remove_artist.jinja' %}
		{% include 'icons/association_cancel.jinja' %}
		</div>

	{% endif %}
{% endblock %}

{% block content %}

<script>
	const entity_id = {{ info.id }};
	const entity_type = 'artist';
	const entity_name = {{ artist | tojson }};
</script>



{% include 'partials/info_artist.jinja' %}


{% set albums_info = dbc.get_albums_artist_appears_on(filterkeys,limitkeys) %}
{% set ownalbums = albums_info.own_albums %}
{% set otheralbums = albums_info.appears_on %}

{% if ownalbums or otheralbums %}

{% if settings['ALBUM_SHOWCASE'] %}
	<h2><a href='{{ mlj_uri.create_uri("/charts_albums",filterkeys) }}'>Albums</a></h2>
	{% include 'partials/album_showcase.jinja' %}
{% else %}
	<h2><a href='{{ mlj_uri.create_uri("/charts_albums",filterkeys) }}'>Top Albums</a></h2>

	{% with amountkeys={"perpage":16,"page":0} %}
	{% include 'partials/charts_albums.jinja' %}
	{% endwith %}
{% endif %}

{% endif %}

{% if info['scrobbles']>0 %}
<h2><a href='{{ mlj_uri.create_uri("/charts_tracks",filterkeys) }}'>Top Tracks</a></h2>

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


<br/>

<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="showStatsManual('pulseperformancecombined','{{ r.identifier }}')"
				class="stat_selector_pulseperformancecombined selector_pulseperformancecombined_{{ 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_pulseperformancecombined pulseperformancecombined_{{ 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",{'artist':credited}) }}'>Performance</a></h2>
			{% if not competes %}<span class="afterheader">of {{ links.link(credited) }}</span>
			{% endif %}
			<br/>

			{% for r in xranges %}
				<span
					onclick="showStatsManual('pulseperformancecombined','{{ r.identifier }}')"
					class="stat_selector_pulseperformancecombined selector_pulseperformancecombined_{{ 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_pulseperformancecombined pulseperformancecombined_{{ r.identifier }}"
				style="{{ 'display:none;' if initialrange!=r.identifier else '' }}"
				>

			{% with filterkeys={'artist':credited},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":16,"page":0} %}
{% include 'partials/scrobbles.jinja' %}
{% endwith %}
{% endif %}

{% endblock %}
