{% from "components/card.html" import stat_card %}

<!-- Summary Cards -->
<div class="grid grid-cols-1 md:grid-cols-3 gap-6">
    {{ stat_card(
        label="Total Team Runs",
        value=(summary.total_teams|default(0)|int)|string,
        icon='<svg class="w-6 h-6" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M17 20h5v-2a3 3 0 00-5.356-1.857M17 20H7m10 0v-2c0-.656-.126-1.283-.356-1.857M7 20H2v-2a3 3 0 015.356-1.857M7 20v-2c0-.656.126-1.283.356-1.857m0 0a5.002 5.002 0 019.288 0M15 7a3 3 0 11-6 0 3 3 0 016 0z"></path></svg>'
    ) }}

    {{ stat_card(
        label="Total Tokens",
        value=(summary.total_tokens|default(0)|format_compact),
        icon='<svg class="w-6 h-6" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"></path></svg>'
    ) }}

    {{ stat_card(
        label="Total Cost",
        value="$" + (summary.total_cost|default(0.0)|float|round(2)|string),
        icon='<svg class="w-6 h-6" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 8c-1.657 0-3 .895-3 2s1.343 2 3 2 3 .895 3 2-1.343 2-3 2m0-8c1.11 0 2.08.402 2.599 1M12 8V7m0 1v8m0 0v1m0-1c-1.11 0-2.08-.402-2.599-1M21 12a9 9 0 11-18 0 9 9 0 0118 0z"></path></svg>'
    ) }}
</div>

<!-- Teams Table -->
{% if summary.teams %}
<div class="bg-white rounded-lg shadow-sm border border-gray-200 overflow-hidden mt-8">
    <div class="px-6 py-4 border-b border-gray-200">
        <h3 class="text-lg font-semibold text-gray-900">Team Run Details</h3>
        <p class="text-sm text-gray-500 mt-1">Each row is one team invocation. Tokens and costs are summed across all team members.</p>
    </div>
    <div class="overflow-x-auto">
        <table class="min-w-full divide-y divide-gray-200">
            <thead class="bg-gray-50">
                <tr>
                    <th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Team Session</th>
                    <th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Members</th>
                    <th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Models</th>
                    <th scope="col" class="px-6 py-3 text-right text-xs font-medium text-gray-500 uppercase tracking-wider">Exchanges</th>
                    <th scope="col" class="px-6 py-3 text-right text-xs font-medium text-gray-500 uppercase tracking-wider">Total Tokens</th>
                    <th scope="col" class="px-6 py-3 text-right text-xs font-medium text-gray-500 uppercase tracking-wider">Cost</th>
                </tr>
            </thead>
            <tbody class="bg-white divide-y divide-gray-200">
                {% for team in summary.teams %}
                <tr class="hover:bg-gray-50 transition-colors">
                    <td class="px-6 py-4">
                        <div class="flex items-center">
                            <div class="flex-shrink-0 h-8 w-8 rounded-full bg-gradient-to-br from-blue-500 to-purple-600 flex items-center justify-center">
                                <span class="text-white text-xs font-bold">{{ team.name[0]|upper }}</span>
                            </div>
                            <div class="ml-3">
                                <div class="text-sm font-medium text-gray-900">{{ team.name }}</div>
                                <div class="text-xs text-gray-400">{{ team.project }}</div>
                            </div>
                        </div>
                    </td>
                    <td class="px-6 py-4">
                        {% if team.members %}
                        <div class="flex flex-col gap-1">
                            {% for m in team.members %}
                            <div class="flex items-center justify-between gap-3">
                                <span class="inline-flex items-center px-2 py-0.5 rounded text-xs font-medium bg-purple-100 text-purple-800"
                                    title="{{ m.exchanges }} exchange(s)">
                                    {{ m.role }}
                                </span>
                                <span class="text-xs text-gray-500">{{ m.tokens|format_compact }}</span>
                                <span class="text-xs font-medium text-[#0770E3]">${{ "%.2f"|format(m.cost) }}</span>
                            </div>
                            {% endfor %}
                        </div>
                        {% else %}
                        <span class="text-xs text-gray-400">—</span>
                        {% endif %}
                    </td>
                    <td class="px-6 py-4">
                        {% if team.model_breakdown %}
                        <div class="flex flex-wrap gap-1">
                            {% for m in team.model_breakdown %}
                            <span class="inline-flex items-center px-2 py-0.5 rounded text-xs font-medium
                                {% if 'opus' in m.model %}bg-amber-100 text-amber-800
                                {% elif 'haiku' in m.model %}bg-emerald-100 text-emerald-800
                                {% else %}bg-indigo-100 text-indigo-800{% endif %}"
                                title="{{ m.model }} — {{ m.tokens|format_compact }} tokens">
                                {{ m.display }}
                            </span>
                            {% endfor %}
                        </div>
                        {% else %}
                        <span class="text-xs text-gray-400">—</span>
                        {% endif %}
                    </td>
                    <td class="px-6 py-4 whitespace-nowrap text-sm text-right text-gray-600">
                        {{ team.exchange_count }}
                    </td>
                    <td class="px-6 py-4 whitespace-nowrap text-sm text-right text-gray-900 font-medium">
                        {{ team.total_tokens|format_compact }}
                    </td>
                    <td class="px-6 py-4 whitespace-nowrap text-sm text-right font-medium text-[#0770E3]">
                        ${{ "%.2f"|format(team.cost) }}
                    </td>
                </tr>
                {% endfor %}
            </tbody>
        </table>
    </div>
</div>
{% else %}
<div class="bg-white rounded-lg shadow-sm border border-gray-200 overflow-hidden mt-8">
    <div class="px-6 py-12 text-center">
        <svg class="mx-auto h-12 w-12 text-gray-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M17 20h5v-2a3 3 0 00-5.356-1.857M17 20H7m10 0v-2c0-.656-.126-1.283-.356-1.857M7 20H2v-2a3 3 0 015.356-1.857M7 20v-2c0-.656.126-1.283.356-1.857m0 0a5.002 5.002 0 019.288 0M15 7a3 3 0 11-6 0 3 3 0 016 0z"></path>
        </svg>
        <p class="mt-2 text-gray-500">No team usage found</p>
        <p class="text-sm text-gray-400 mt-1">Use the Teams feature in Claude Code to see team analytics</p>
    </div>
</div>
{% endif %}
