{% set mine_users = (state.usernames | default({})).values() | list %}
{% if issues %}
{% set mine_count = [] %}
{% set closed_count = [] %}
{% for i in issues %}
    {% set _involved = i.author in mine_users or (i.assignees | default([]) | select("in", mine_users) | list | length > 0) or (i.participants | default([]) | select("in", mine_users) | list | length > 0) %}
    {% if _involved %}{% if mine_count.append(1) %}{% endif %}{% endif %}
    {% if i.state == "closed" %}{% if closed_count.append(1) %}{% endif %}{% endif %}
{% endfor %}

<div class="stats-bar">
    <div class="stat-chip">
        <span class="stat-chip-value">{{ issues | length }}</span>
        <span class="stat-chip-label">total</span>
    </div>
    {% if mine_count %}
    <div class="stat-chip stat-chip-accent">
        <span class="stat-chip-value">{{ mine_count | length }}</span>
        <span class="stat-chip-label">mine</span>
    </div>
    {% endif %}
    {% if closed_count %}
    <div class="stat-chip stat-chip-success">
        <span class="stat-chip-value">{{ closed_count | length }}</span>
        <span class="stat-chip-label">closed</span>
    </div>
    {% endif %}
</div>

<table class="sortable">
    <thead>
        <tr>
            <th>Repo</th>
            <th>Title</th>
            <th>Author</th>
            <th>Labels</th>
            <th>Assignees</th>
            <th>Status</th>
            <th class="no-sort">Info</th>
        </tr>
    </thead>
    <tbody>
        {% for i in issues %}
        {% set _involved = i.author in mine_users or (i.assignees | default([]) | select("in", mine_users) | list | length > 0) or (i.participants | default([]) | select("in", mine_users) | list | length > 0) %}
        <tr class="{% if _involved %}row-mine{% endif %}{% if i.confidential %} row-confidential{% endif %}">
            <td><a href="/repo/{{ i.repo_name }}?from=issues"><code>{{ i.repo_name }}</code></a></td>
            <td>
                <a href="{{ i.web_url }}" target="_blank">{% if i.confidential %}&#x1F512; {% endif %}{{ i.title }}</a>
                <span class="mr-iid">#{{ i.iid }}</span>
            </td>
            <td>{{ i.author }}</td>
            <td>{% for l in (i.labels | default([])) %}<span class="label-badge">{{ l }}</span> {% endfor %}</td>
            <td>{{ (i.assignees | default([])) | join(", ") }}</td>
            <td><span class="badge-{{ i.state }}">{{ i.state }}</span></td>
            <td class="info-cell">
                {% if i.user_notes_count %}
                <span class="comment-count" title="{{ i.user_notes_count }} comments">
                    <svg class="inline-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"/></svg>
                    {{ i.user_notes_count }}
                </span>
                {% endif %}
            </td>
        </tr>
        {% endfor %}
    </tbody>
</table>
{% else %}
<p class="text-center-muted">No open issues.</p>
{% endif %}
