<section class="summary-panel">
  <% if @issues.any? %>
    <h4 class="header-underline">Issues so far</h4>
    <div id="issue-chart"></div>

    <div id="issues-accordion" role="tablist">
      <% for tag in @tags do %>
        <% if @issues_by_tag[tag.name].any? %>
          <div class="card" style="border-color: <%= tag.color %>">
            <a data-bs-toggle="collapse" href="#collape<%= tag.display_name %>" class="card-header" style="background: <%= tag.color %>" data-behavior="card-header">
              <h5><%= tag.display_name %><span class="float-end"><i class="fa-solid fa-caret-up" data-behavior="caret-icon"></i></span></h5>
            </a>

            <div id="collape<%= tag.display_name %>" class="collapse show">
              <div class="card-body p-0">
                <ul class="list-group">
                  <% @issues_by_tag[tag.name].each do |issue| %>
                    <%= link_to [current_project, issue], class: 'list-group-item'  do %>
                      <li><i class="fa-solid fa-bug me-2" style="color: <%= tag.color %>"></i><%= issue.title %></li>
                    <% end %>
                  <% end %>
                </ul>
              </div>
            </div>
          </div>
        <% end %>
      <% end %>

      <%# unassigned %>
      <% if @issues_by_tag[:unassigned].any? %>
        <div class="card untagged">
          <a data-bs-toggle="collapse" href="#collapeUnassigned" class="card-header" data-behavior="card-header">
            <h5>Unassigned<span class="float-end"><i class="fa-solid fa-caret-up" data-behavior="caret-icon"></i></span></h5>
          </a>

          <div id="collapeUnassigned" class="collapse show">
            <div class="card-body p-0">
              <ul class="list-group">
                <% @issues_by_tag[:unassigned].each do |issue| %>
                  <%= link_to [current_project, issue], class: 'list-group-item'  do %>
                    <li><i class="fa-solid fa-bug me-2"></i><%= issue.title %></li>
                  <% end %>
                <% end %>
              </ul>
            </div>
          </div>
        </div>
      <% end %>
    </div>

  <% else %>
    <%= render 'shared/empty_state',
      actions_partial: 'projects/issues/empty_state_actions',
      name: 'issue',
      docs_link: 'https://dradis.com/support/guides/projects/issues.html',
      text: 'Use issues to represent vulnerabilities or findings.'
    %>
  <% end %>
</section>

<% if @issues.any? %>
  <div id='issues-summary-data' data-tags='<%= @tag_names.to_json %>' data-issues-count='<%= @count_by_tag.to_json %>'></div>
<% end %>
