{% from 'magpie/parts.html' import client, provider, integer, count, estimate, failure with context %}
{% if errors.get('usage') %}{{ failure(errors['usage'], t) }}{% else %}
{% for label, icon, total in [ ('calls', 'magpie/icons/activity.svg', integer(usage.get('calls'))), ('errors', 'magpie/icons/triangle-alert.svg', integer(usage.get('errors'))), ('tokens', 'magpie/icons/coins.svg', count(totals_tokens(usage))), ('cost', 'magpie/icons/coins.svg', estimate(usage.get('cost'), 2)) ] %}
{% include icon %}{{ t.text('magpie.usage.' ~ label) }}
{{ total }}
{% endfor %}
{% endif %}

{{ t.text('magpie.usage.trend') }}

{{ t.text('magpie.usage.' ~ ('hour' if usage.get('bucket') == 'hour' else 'day')) }}
{% if bars %} {% set stride = 6 if usage.get('bucket') == 'hour' else (2 if bars | length <= 8 else (bars | length) // 4) %} {% else %}

{{ t.text('magpie.usage.empty') }}

{% endif %}

{{ t.text('magpie.usage.agents') }}

{% for row in usage.get('agents') or [] %}
{{ client(row.id, source_name(row.id, row.get('name','')), row.get('icon','')) }}{{ count(totals_tokens(row)) }} Token{{ estimate(row.get('cost'), 2) }}
{% else %}

{{ t.text('magpie.usage.empty') }}

{% endfor %}

{{ t.text('magpie.quota.title') }}

{% if errors.get('quotas') %}{{ failure(errors['quotas'], t) }}{% else %} {% for quota in quotas %} {% else %}

{{ t.text('magpie.quota.empty') }}

{% endfor %} {% endif %}