{% extends "crashstats_base.html" %}
{% block site_css %}
  {{ super() }}
  {% compress css %}
    <link rel="stylesheet" type="text/less" href="{{ static('crashstats/css/tcr_bybug.less') }}" media="screen" />
  {% endcompress %}
{% endblock %}

{% block page_title %}
Top Crashing Signatures {% if bug_number %}For Bug {{ bug_number }} {% endif %}
{% endblock %}

{% block content %}
    <main role="main">
        <header>
            <h2>Top Crashing Signatures {% if bug_number %}For Bug {{ bug_number }} {% endif %}</h2>
        </header>

        <form name="bug_signatures" id="bug_signatures" class="bug-signatures" action="{{ url('crashstats.topcrasher_ranks_bybug') }}" method="get">
            <fieldset>
                <legend class="visually-hidden">Find Signatured for Bug Number</legend>
                <label for="bug_number">Bug Number:</label>
                <input type="text" name="bug_number" id="bug_number" required="true" />
                <input type="submit" value="Find Signatures" />
            </fieldset>
        </form>

        <section id="signature-details">
            {% if signatures|length > 0 %}
                {% for signature in signatures %}
                <table class="captioned-data-table tcr-signature initially-hidden" aria-expanded="false">
                    <caption>
                        <a href="">{{ signature['signature'] }}</a>
                        <a href="javascript:void(0)" class="toggle-sig-details" title="Show Details">
                            <span aria-hidden="true" class="expander-icon" data-icon="&#xe803;"></span>
                        </a>
                    </caption>
                    <thead>
                        <tr>
                            <th>Rank</th>
                            <th>Product</th>
                            <th>Version</th>
                            <th>Process Type</th>
                        </tr>
                    </thead>
                    <tbody>
                    {% for signature in top_crashes_by_signature %}
                      {% for product in top_crashes_by_signature[signature] %}
                        {% for version in top_crashes_by_signature[signature][product] %}
                          {% if top_crashes_by_signature[signature][product][version] %}
                        <tr>
                            <td>{{ top_crashes_by_signature[signature][product][version][0]['currentRank']|int + 1}}</td>
                            <td>{{ product }}</td>
                            <td>{{ version }}</td>
                            <td>
                                {% if top_crashes_by_signature[signature][product][version][0]['plugin_count'] == 0 %}
                                Browser
                                {% else %}
                                Plugin
                                {% endif %}
                            </td>
                        </tr>
                          {% endif %}
                        {% endfor %}
                      {% endfor %}
                    {% endfor %}
                    </tbody>
                </table>
                {% endfor %}
            {% elif bug_number %}
                <!-- Only show the message if a bug number exists else, this is first load. -->
                <p class="info">No signatures found for bug id {{ bug_number }}.</p>
            {% endif %}
        </section>
    </main>
{% endblock %}

{% block site_js %}
  {{ super() }}
  {% compress js %}
  <script src="{{ static('crashstats/js/socorro/utils.js') }}"></script>
  <script src="{{ static('crashstats/js/socorro/tcr_bybug.js') }}"></script>
  {% endcompress %}
{% endblock %}
