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

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

{% 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 track = e.track %}
	<tr>
		<td><a href="{{ mlj_uri.create_uri("/charts_tracks",{'timerange':thisrange}) }}">{{ thisrange.desc() }}</a></td>

		{% if track is none %}
			<td><div></div></td>
			<td class='stats'>n/a</td>
			<td class='amount'>0</td>
			<td class='bar'></td>
		{% else %}
		{{ entityrow.row(track) }}
			<td class='amount'>{{ links.link_scrobbles([{'track':track,'timerange':thisrange}],amount=e.scrobbles) }}</td>
			<td class='bar'> {{ links.link_scrobbles([{'track':track,'timerange':thisrange}],percent=e.scrobbles*100/maxbar) }}</td>
		{% endif %}

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