{# Copyright 2022, Red Hat, Inc. #}
{# SPDX-License-Identifier: LGPL-2.1-or-later #}
<table class="pf-c-table pf-m-expandable pf-m-grid-lg" role="grid" id="rule-table">
    <thead>
        <tr role="row">
            <th></th>
            <th class="pf-c-table__sort" role="columnheader">
                <span class="pf-c-table__text">Rule</span>
            </th>
            <th class="pf-c-table__sort" role="columnheader">
                <span class="pf-c-table__text">Severity</span>
            </th>
            <th class="pf-c-table__sort" role="columnheader">
                <span class="pf-c-table__text">Result</span>
            </th>
        </tr>
    </thead>
    {%- set rule_hidden = "" -%}
    {% for rule_id, rule in report.get_selected_rules() %}
    {%- if rule.result != "notselected" -%}
        {%- set rule_title = rule.title  -%}
        {%- if rule_title == "" -%}
            {%- set rule_title = rule_id  -%}
        {%- endif -%}
        {% if loop.index > 50 %}
            {%- set rule_hidden = "hidden" -%}
        {% endif %}
    <tbody class="pf-m-expanded {{ rule_hidden }}" role="rowgroup" rule-title="{{ rule_title }}" rule-id="{{ rule.rule_id }}" result="{{ rule.result }}" severity="{{ rule.severity }}">
        <tr role="row">
            <td class="pf-c-table__toggle" role="cell">
                <button
                    id="show_hide_rule_detail_button"
                    class="pf-c-button pf-m-plain" onclick="show_rule_detail(this);"
                    aria-label="Show details of rule (rule_id:{{ rule.rule_id }})"
                    title="Show details of rule (rule_id:{{ rule.rule_id }})"
                >
                    <div class="pf-c-table__toggle-icon">
                        <i class="fas fa-angle-down" aria-hidden="true"></i>
                    </div>
                </button>
            </td>

            <td role="cell" id="title_{{ rule.rule_id }}" class="rule-title" data-label="Rule">
                <button class="pf-c-button pf-m-plain clickable-element" onclick="show_rule_detail_after_click_on_rule_title(this);">
                    <span class="pf-c-table__text">{{ rule_title }}</span>
                </button>
            </td>

            <td role="cell" class="rule-severity" data-label="Severity">
                {% if rule.result not in ("pass", "fixed") and rule.severity == "low" %}
                <span class="pf-c-label pf-m-blue">
                    <span class="pf-c-label__content">{{ rule.severity }}</span>
                </span>
                {% elif rule.result not in ("pass", "fixed") and rule.severity == "medium" %}
                <span class="pf-c-label pf-m-orange">
                    <span class="pf-c-label__content">{{ rule.severity }}</span>
                </span>
                {% elif rule.result not in ("pass", "fixed") and rule.severity == "high" %}
                <span class="pf-c-label pf-m-red">
                    <span class="pf-c-label__content">{{ rule.severity }}</span>
                </span>
                {% else %}
                <span class="pf-c-label">
                    <span class="pf-c-label__content">{{ rule.severity }}</span>
                </span>
                {% endif %}
            </td>
            <td role="cell" class="rule-result" data-label="Result">
                {% if rule.result in ("pass", "fixed") %}
                <span class="pf-c-label pf-m-green">
                    <span class="pf-c-label__content">
                        <span class="pf-c-label__icon">
                            <i class="fas fa-fw fa-check" aria-hidden="true"></i>
                        </span>
                        {{- rule.result -}}
                    </span>
                </span>
                {% elif rule.result in ("fail", "error", "fix unsuccessful", "fix failed") %}
                <span class="pf-c-label pf-m-red">
                    <span class="pf-c-label__content">
                        <span class="pf-c-label__icon">
                            <i class="fas fa-fw fa-times" aria-hidden="true"></i>
                        </span>
                        {{- rule.result -}}
                    </span>
                </span>
                {% else %}
                <span class="pf-c-label">
                    <span class="pf-c-label__content">
                        <span class="pf-c-label__icon">
                            <i class="fas fa-fw fa-question-circle" aria-hidden="true"></i>
                        </span>
                    {{- rule.result -}}
                    </span>
                </span>
                {% endif %}
            </td>
        </tr>
        <tr class="pf-c-table__expandable-row disable-scrollbar-for-low-resolution" role="row">
            <td role="cell" colspan="4">
                <div class="pf-c-table__expandable-row-content">
                    {% include 'rule_detail.html' %}
                </div>
            </td>
        </tr>
    </tbody>
    {% endif %}
    {% endfor %}
</table>
