<!--
# Copyright lowRISC contributors (OpenTitan project).
# Licensed under the Apache License, Version 2.0, see LICENSE for details.
# SPDX-License-Identifier: Apache-2.0

-->
{% set top = summary.top %}
{% set timestamp = summary.timestamp %}
<div class="container-md"> 
    <div class="row">
        <div class="col">
            {% if breadcrumbs %}
            <nav aria-label="breadcrumb">
                <ol class="breadcrumb">
                    {% for c in breadcrumbs[:-1] %}
                        <li class="breadcrumb-item"><a href="{{ c[0] }}">{{ c[1] }}</a></li>
                    {% endfor %}
                    <li class="breadcrumb-item active" aria-current="page">
                        {{ breadcrumbs[-1][1] if breadcrumbs[-1] is iterable and breadcrumbs[-1]|length == 2 else breadcrumbs[-1] }}
                    </li>
                </ol>
            </nav>
            {% endif %}
        </div>
    </div>

    <div class="row py-3">
        <div class="col">
            <h2>Simulation Results: {{ top.name }}</h2>
        </div>
    </div>

    <div class="row">
        <div class="col-4 col-md-3">
            <div class="text-center mb-2">&nbsp;</div>
            <span class="badge text-bg-secondary">
                {{ timestamp.strftime("%d/%m/%Y %H:%M:%S") }}
            </span>
            <a class="badge text-bg-secondary link-underline link-underline-opacity-0"
                href="{{ top.url }}">
                sha: {{ top.commit[:7] }}
            </a>
            <a class="badge text-bg-secondary link-underline link-underline-opacity-0"
                href="index.json">json</a>
            <span class="badge text-bg-secondary">
                Branch: {{ top.branch }}
            </span>
        </div>
    </div>

    {% macro coverage_cell(cov, kind) %}
    {% if cov and cov|attr(kind) is not none %}
        {% set value = cov|attr(kind) %}
        <td class="c{{ (value / 10)|int }}">{{ "%.2f"|format(value) }}</td>
    {% else %}
        <td class="text-muted">-</td>
    {% endif %}
    {% endmacro %}

    <div class="row py-3">
        <div class="col">
            <table class="table table-sm table-hover text-center">
                <thead class="table-light align-middle">
                    <tr>
                        <th rowspan="2">Block</th>
                        <th colspan="3">Tests</th>
                        <th colspan="4" class="bg-secondary text-white">Coverage Summary</th>
                        <th colspan="6">Code Coverage</th>
                    </tr>
                    <tr>
                        <!-- Tests sub-headers -->
                        <th>Pass</th>
                        <th>Total</th>
                        <th>%</th>

                        <!-- Coverage Summary sub-headers -->
                        <th class="bg-secondary text-white">Overall</th>
                        <th class="bg-secondary text-white">Code</th>
                        <th class="bg-secondary text-white">Functional</th>
                        <th class="bg-secondary text-white">Assertion</th>

                        <!-- Code Coverage sub-headers -->
                        <th>Block</th>
                        <th>Line</th>
                        <th>Branch</th>
                        <th>Condition</th>
                        <th>Toggle</th>
                        <th>FSM</th>
                    </tr>
                </thead>
                <tbody>
                    {% for block_name in summary.flow_results.keys()|sort %}
                        {% set flow = summary.flow_results[block_name] %}
                        <tr>
                            <td class="btn"
                                hx-get="{{ block_name }}.html"
                                hx-trigger="click"
                                hx-push-url="true"
                                hx-target="#report-content">
                                    {{ block_name | upper }}
                            </td>
                            <td>{{ flow.passed }}</td>
                            <td>{{ flow.total }}</td>
                            <td class="c{{ (flow.percent / 10)|int }}">
                                {{ "%.2f" | format(flow.percent) }}
                            </td>
                            {% set cov = flow.coverage %}
                            {{ coverage_cell(cov, "average") }}

                            {% set code = cov|attr("code") %}
                            {{ coverage_cell(code, "average") }}
                            {{ coverage_cell(cov, "functional") }}
                            {{ coverage_cell(cov, "assertion") }}

                            {{ coverage_cell(code, "block") }}
                            {{ coverage_cell(code, "line_statement") }}
                            {{ coverage_cell(code, "branch") }}
                            {{ coverage_cell(code, "condition_expression") }}
                            {{ coverage_cell(code, "toggle") }}
                            {{ coverage_cell(code, "fsm") }}
                        </tr>
                    {% endfor %}
                </tbody>
            </table>
        </div>
    </div>
</div>
