{%- extends "_layout.html" %}

{%- block content %}

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

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

                    </div>
                    <p>
                        <small>
                            <strong>{{ _('Group 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>
                        <li role="presentation" class="nav-item">
                            <a href="#tab-networks" aria-controls="tab-networks" role="tab" data-bs-toggle="tab" class="nav-link">
                                <strong>{{ get_icon('module-networks') }} {{ _('Networks') }}</strong> <span class="badge rounded-pill  text-bg-secondary">{{ item.networks | length }}</span>
                            </a>
                        </li>
                        <li role="presentation" class="nav-item">
                            <a href="#tab-filters" aria-controls="tab-filters" role="tab" data-bs-toggle="tab" class="nav-link">
                                <strong>{{ get_icon('module-filters') }} {{ _('Filters') }}</strong> <span class="badge rounded-pill  text-bg-secondary">{{ item.filters | length }}</span>
                            </a>
                        </li>
                        {%- if can_access_endpoint('groups.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>
                            <div class="row">
                                <div class="col-md-4">
                                    <h5>{{ _('Metadata') }}</h5>
                                    <table class="table table-striped">
                                        <tbody>
                                            <tr>
                                                <th>
                                                    {{ _('Parent group') }}:
                                                </th>
                                                <td>
                                                    {%- if item.parent %}
                                                    <a data-bs-toggle="tooltip" href="{{ url_for('groups.show', item_id = item.parent.id ) }}" title="{{ _('View details of group &quot;%(item)s&quot;', item = item.parent.name) }}">
                                                        {{ item.parent.name }}
                                                    </a>
                                                    {%- else %}
                                                    {{ _('<< none >>') }}
                                                    {%- endif %}
                                                </td>
                                            </tr>
                                            <tr>
                                                <th>
                                                    {{ _('Source') }}:
                                                </th>
                                                <td>
                                                    {{ item.source | default(_('<< unknown >>'), True) }}
                                                </td>
                                            </tr>
                                            <tr>
                                                <th>
                                                    {{ _('State') }}:
                                                </th>
                                                <td>
                                                    {{ macros_site.render_label_item_state(item.enabled, True) }}
                                                </td>
                                            </tr>
                                            <tr>
                                                <th>
                                                    {{ _('Reporting settings') }}:
                                                </th>
                                                <td>
                                                    <a role="button" class="btn btn-outline-dark btn-sm" data-bs-toggle="tooltip" href="{{ url_for('settings_reporting.show', item_id = item.settings_rep.id ) }}" title="{{ _('View details of reporting settings for group &quot;%(item)s&quot;', item = item.name) }}">
                                                        {{ get_icon('module-settings-reporting') }} {{ _('View reporting settings') }}
                                                    </a>
                                                </td>
                                            </tr>
                                            {%- if permission_can('admin') or permission_can('maintainer') %}
                                            <tr>
                                                <th>
                                                    {{ _('Local ID') }}:
                                                </th>
                                                <td>
                                                    {{ item.local_id | default(_('<< none >>'), True) }}
                                                </td>
                                            </tr>
                                            {%- endif %}
                                        </tbody>
                                    </table>
                                </div>

                                <div class="col-md-4">
                                    {%- if item.members_wanted %}
                                    <h5>
                                        {{ _('Membership requests') }} <span class="badge rounded-pill text-bg-secondary my-n2">{{ item.members_wanted | length }}</span>
                                    </h5>
                                    <table class="table table-striped">
                                        <tbody>
                                            {%- for subitem in item.members_wanted %}
                                            <tr>
                                                <td{%- if not subitem.enabled %} class="text-muted"{% endif %}>
                                                    {{ subitem.login }}
                                                </td>
                                                <td{%- if not subitem.enabled %} class="text-muted"{% endif %}>
                                                    {{ subitem.fullname }}
                                                </td>
                                                <td>
                                                    {{ macros_page.render_menu_context_actions(subitem, context_action_menu_users, kwargs = {'other': item}) }}
                                                </td>
                                            </tr>
                                            {%- endfor %}
                                        </tbody>
                                    </table>
                                    {%- endif %}
                                    <h5>
                                        {{ _('Members') }} <span class="badge rounded-pill text-bg-secondary my-n2">{{ item.members | length }}</span>
                                    </h5>
                                    {%- if item.members %}
                                    <table class="table table-striped">
                                        <tbody>
                                            {%- for subitem in item.members %}
                                            <tr>
                                                <td{%- if not subitem.enabled %} class="text-muted"{% endif %}>
                                                    {{ subitem.login }}
                                                </td>
                                                <td{%- if not subitem.enabled %} class="text-muted"{% endif %}>
                                                    {{ subitem.fullname }}
                                                </td>
                                                <td>
                                                    {{ macros_page.render_menu_context_actions(subitem, context_action_menu_users, kwargs = {'other': item}) }}
                                                </td>
                                            </tr>
                                            {%- endfor %}
                                        </tbody>
                                    </table>
                                    {%- else %}
                                    {%- call macros_site.render_alert('info', False) %}
                                    {{ _('This group does not have any members defined at the moment.') }}
                                    {%- endcall %}
                                    {%- endif %}
                                </div>

                                <div class="col-md-4">
                                    <h5>{{ _('Managers') }} <span class="badge rounded-pill text-bg-secondary my-n2">{{ item.managers | length }}</span></h5>
                                    {%- if item.managers %}
                                    <table class="table table-striped">
                                        <tbody>
                                            {%- for subitem in item.managers %}
                                            <tr>
                                                <td>
                                                    {{ subitem.login }}
                                                </td>
                                                <td>
                                                    {{ subitem.fullname }}
                                                </td>
                                                <td>
                                                    {{ macros_page.render_menu_context_actions(subitem, context_action_menu_users, kwargs = {'other': item}) }}
                                                </td>
                                            </tr>
                                            {%- endfor %}
                                        </tbody>
                                    </table>
                                    {%- else %}
                                    {%- call macros_site.render_alert('info', False) %}
                                    {{ _('This group does not have any managers defined at the moment.') }}
                                    {%- endcall %}
                                    {%- endif %}
                                </div>

                            </div>
                        </div>

                        <div role="tabpanel" class="tab-pane fade" id="tab-networks">
                            <br>
                            {%- if item.networks %}
                            <table class="table table-striped">
                                <tbody>
                                    {%- for subitem in item.networks %}
                                    <tr>
                                        <td>
                                            {{ subitem.netname | default(_('<< unknown >>'), True) }}
                                        </td>
                                        <td>
                                            {{ macros_site.render_widget_csag_address([subitem.network], separate_dropdown = True) }}
                                        </td>
                                        <td>
                                            {{ macros_page.render_menu_context_actions(subitem, context_action_menu_networks) }}
                                        </td>
                                    </tr>
                                    {%- endfor %}
                                </tbody>
                            </table>
                            {%- else %}
                            {%- call macros_site.render_alert('info', False) %}
                            {{ _('This group does not have any network records defined at the moment.') }}
                            {%- endcall %}
                            {%- endif %}

                            {%- if can_access_endpoint('networks.createfor', item) %}
                            <br>
                            <div class="clearfix">
                                <div class="float-end">
                                    <div class="btn-toolbar" role="toolbar" aria-label="Action toolbar">
                                        <div class="btn-group btn-group-sm" role="group" aria-label="Action buttons">
                                            <a role="button" class="btn btn-secondary btn-sm" href="{{ url_for('networks.createfor', parent_id=item.id ) }}" data-bs-toggle="tooltip" title="{{ _('Create network record') }}">
                                                <i class="fas fa-fw fa-plus-circle"></i><span class="d-none d-lg-inline"> {{ _('Create network record') }}</span>
                                            </a>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            {%- endif %}

                        </div>

                        <div role="tabpanel" class="tab-pane fade" id="tab-filters">
                            <br>
                            {%- if item.filters %}
                            <div class="table-responsive">
                                <table class="table table-striped">
                                    <tbody>
                                        {%- for subitem in item.filters -%}
                                        <tr>
                                            <td>
                                                {{ subitem.name | default(_('<< unknown >>'), True) }}
                                            </td>
                                            <td class="breakable-code-snippet">
                                                {% for s in iter_separated(subitem.filter) %}<code>{{ s }}</code>{% endfor %}
                                            </td>
                                            <td>
                                                <span class="badge rounded-pill  text-bg-secondary">{{ subitem.hits }}</span>
                                            </td>
                                            <td>
                                                {{ macros_site.render_label_item_state(subitem.enabled, True) }}
                                            </td>
                                            <td>
                                                {{ macros_page.render_menu_context_actions(subitem, context_action_menu_filters) }}
                                            </td>
                                        </tr>
                                        {%- endfor %}
                                    </tbody>
                                </table>
                            </div>
                            {%- else %}
                            {%- call macros_site.render_alert('info', False) %}
                            {{ _('This group does not have any reporting filters defined at the moment.') }}
                            {%- endcall %}
                            {%- endif %}

                            {%- if can_access_endpoint('filters.createfor', item) %}
                            <br>
                            <div class="clearfix">
                                <div class="float-end">
                                    <div class="btn-toolbar" role="toolbar" aria-label="Action toolbar">
                                        <div class="btn-group btn-group-sm" role="group" aria-label="Action buttons">
                                            <a role="button" class="btn btn-secondary btn-sm" href="{{ url_for('filters.createfor', parent_id = item.id ) }}" data-bs-toggle="tooltip" title="{{ _('Create reporting filter') }}">
                                                <i class="fas fa-fw fa-plus-circle"></i><span class="d-none d-lg-inline"> {{ _('Create reporting filter') }}</span>
                                            </a>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            {%- endif %}

                        </div>

                        {%- if can_access_endpoint('groups.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 group 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) }}

    {%- endif %}

{%- endblock content %}
