{%- extends "_layout.html" %}

{%- block content %}

                <div>
                    {{ macros_page.render_breadcrumbs(item) }}

                    <h3>{{ item.name }}</h3>
                    <div class="float-end">
                        {{ macros_page.render_menu_actions(item) }}

                    </div>
                    <p>
                        <small>
                            <strong>{{ _('Filter created') }}:</strong> {{ babel_format_datetime(item.createtime) }} ({{ _('%(delta)s ago', delta = babel_format_timedelta(current_datetime_utc - item.createtime)) }})
                        </small>
                    </p>
                    <br>

                    <!-- Nav tabs -->
                    <ul class="nav nav-tabs" role="tablist">
                        <li role="presentation" class="nav-item">
                            <a href="#tab-general" aria-controls="tab-general" role="tab" data-bs-toggle="tab" class="nav-link active">
                                <strong>{{ get_icon('alert-info') }} {{ _('General information') }}</strong>
                            </a>
                        </li>
                        {%- if filter_preview %}
                        <li role="presentation" class="nav-item">
                            <a href="#tab-tree" aria-controls="tab-tree" role="tab" data-bs-toggle="tab" class="nav-link">
                                <strong>{{ get_icon('structure') }} {{ _('Filter tree structure') }}</strong>
                            </a>
                        </li>
                        {%- endif %}
                        {%- if can_access_endpoint('filters.update', item) %}
                        <li role="presentation" class="nav-item">
                            <a href="#tab-changelog" aria-controls="tab-changelog" role="tab" data-bs-toggle="tab" class="nav-link">
                                <strong>{{ get_icon('module-changelogs') }} {{ _('Changelogs') }}</strong> <span class="badge rounded-pill text-bg-secondary">{{ item_changelog | length }}</span>
                            </a>
                        </li>
                        {%- endif %}
                    </ul>

                    <!-- Tab panes -->
                    <div class="tab-content">

                        <div role="tabpanel" class="tab-pane fade in show active" id="tab-general">
                            <br>
                            <table class="table table-striped">
                                <tbody>
                                    <tr>
                                        <th>
                                            {{ _('Group') }}:
                                        </th>
                                        <td>
                                            <a data-bs-toggle="tooltip" href="{{ url_for('groups.show', item_id = item.group.id ) }}" title="{{ _('View details of group &quot;%(item)s&quot;', item = item.group.name) }}">
                                                {{ item.group.name }}
                                            </a>
                                        </td>
                                    </tr>
                                    <tr>
                                        <th>
                                            {{ _('Name') }}:
                                        </th>
                                        <td>
                                            {{ item.name | default(_('<< unknown >>'), True) }}
                                        </td>
                                    </tr>
                                    <tr>
                                        <th>
                                            {{ _('Description') }}:
                                        </th>
                                        <td>
                                            {{ item.description | default(_('<< unknown >>'), True) }}
                                        </td>
                                    </tr>
                                    <tr>
                                        <th>
                                            {{ _('Filtering:') }}
                                        </th>
                                        <td>
                                            {{ _('summary and extra reports') if item.source_based else _('target reports') }}
                                        </td>
                                    </tr>
                                    <tr>
                                        <th>
                                            {{ _('Type') }}:
                                        </th>
                                        <td>
                                            {{ item.type | default(_('<< unknown >>'), True) }}
                                        </td>
                                    </tr>
                                    <tr>
                                        <th>
                                            {{ _('Filter') }}:
                                        </th>
                                        <td>
                                            <code>{{ item.filter | default(_('<< unknown >>'), True) }}</code>
                                        </td>
                                    </tr>
                                    <tr>
                                        <th>
                                            {{ _('Hits') }}:
                                        </th>
                                        <td>
                                            <span class="badge rounded-pill  text-bg-secondary">{{ item.hits }}</span>
                                        </td>
                                    </tr>
                                    <tr>
                                        <th>
                                            {{ _('Last hit') }}:
                                        </th>
                                        <td>
                                            <span>{% if item.last_hit %}{{ babel_format_datetime(item.last_hit) }}{% else %}---{% endif %}</span>
                                        </td>
                                    </tr>
                                    <tr>
                                        <th>
                                            {{ _('Valid from:') }}
                                        </th>
                                        <td>
                                            <span>{% if item.valid_from %}{{ babel_format_datetime(item.valid_from) }}{% else %}---{% endif %}</span>
                                        </td>
                                    </tr>
                                    <tr>
                                        <th>
                                            {{ _('Valid to:') }}
                                        </th>
                                        <td>
                                            <span>{% if item.valid_to %}{{ babel_format_datetime(item.valid_to) }}{% else %}---{% endif %}</span>
                                        </td>
                                    </tr>
                                    <tr>
                                        <th>
                                            {{ _('State') }}:
                                        </th>
                                        <td>
                                            {{ macros_site.render_label_item_state(item.enabled, True) }}
                                        </td>
                                    </tr>
                                </tbody>
                            </table>
                        </div>

                        {%- if filter_preview %}
                        <div role="tabpanel" class="tab-pane fade" id="tab-tree">
                            <br>
                            <div class="rule-tree">
                                {{ filter_preview | safe }}
                            </div>
                            <hr>
                            <h4>{{ _('Textual representation') }}:</h4>
<pre>
{{ filter_tree.__str__() }}
</pre>
                        </div>
                        {%- endif %}

                        {%- if can_access_endpoint('filters.update', item) %}
                        <div role="tabpanel" class="tab-pane fade" id="tab-changelog">
                            <br>
                            {%- if item_changelog %}
                            {{ macros_page.render_changelog_records(item_changelog, context_action_menu_changelogs) }}
                            <p>
                                <small>
                                    {{ _('Displaying only latest %(count)s changelogs', count = 100) }}
                                </small>
                            </p>
                            {%- else %}
                            {%- call macros_site.render_alert('info', False) %}
                            {{ _('This object does not have any changelog records at the moment.') }}
                            {%- endcall %}
                            {%- endif %}
                        </div>
                        {%- endif %}

                    </div>

                </div>

    {%- if permission_can('developer') %}

            <hr>

            {{ macros_site.render_raw_item_view(item) }}
            {{ macros_site.render_raw_var('filter_tree',             filter_tree) }}
            {{ macros_site.render_raw_var('filter_compiled',         filter_compiled) }}
            {{ macros_site.render_raw_var('filter_preview',          filter_preview) }}
            {{ macros_site.render_raw_var('filter_compiled_preview', filter_compiled_preview) }}

    {%- endif %}

{%- endblock content %}
