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

{% set ranges = dbc.get_top_artists(limitkeys,delimitkeys,specialkeys) %}

{% set maxbar = ranges|map(attribute="scrobbles")|max|default(1) %}
{% if maxbar < 1 %}{% set maxbar = 1 %}{% endif %}

<table class="list">
	{% for e in ranges %}

	{% set thisrange = e.range %}
	{% set artist = e.artist %}
	<tr>
		<td><a href="{{ mlj_uri.create_uri("/charts_artists",{'timerange':thisrange},specialkeys) }}">{{ thisrange.desc() }}</a></td>

		{% if artist is none %}
			<td><div></div></td>
			<td class='stats'>n/a</td>
			<td class='amount'>0</td>
			<td class='bar'></td>
		{% else %}
		{{ entityrow.row(artist,counting=([] if specialkeys.separate else e.associated_artists)) }}
		<td class='amount'>{{ links.link_scrobbles([{'artist':artist,'associated':(not specialkeys.separate),'timerange':thisrange}],amount=e.scrobbles) }}</td>
		<td class='bar'>
		    {{ links.link_scrobbles([{'artist':e['artist'],'associated':False,'timerange':e.range}],percent=e['real_scrobbles']*100/maxbar) }}
            {%- if e['real_scrobbles'] != e['scrobbles'] -%}
            {{ links.link_scrobbles([{'artist':e['artist'],'associated':True,'timerange':e.range}],percent=(e['scrobbles']-e['real_scrobbles'])*100/maxbar) }}
            {%- endif %}
		</td>
		{% endif %}

	</tr>
	{% endfor %}
</table>
