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

{% set ranges = dbc.get_pulse(filterkeys,limitkeys,delimitkeys) %}

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

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

	{% set thisrange = t.range %}
	<tr>
		<td class="timerange">{{ thisrange.desc() }}</td>
		<td class="amount">
			{{ links.link_scrobbles([filterkeys,{'timerange':thisrange}],amount=t.scrobbles) }}
		</td>
		<td class="bar">
		    {% if 'artist' in filterkeys and filterkeys.get('associated') %}
		        {{ links.link_scrobbles([{'artist':filterkeys.artist,'associated':False,'timerange':thisrange}],percent=t.real_scrobbles*100/maxbar) }}
                {%- if t.real_scrobbles != t.scrobbles -%}
                {{ links.link_scrobbles([{'artist':filterkeys.artist,'associated':True,'timerange':thisrange}],percent=(t.scrobbles-t.real_scrobbles)*100/maxbar) }}
                {%- endif %}
		    {% else %}
		        {{ links.link_scrobbles([filterkeys,{'timerange':thisrange}],percent=t.scrobbles*100/maxbar) }}
		    {% endif %}
		</td>
	</tr>
	{% endfor %}
</table>
