{% extends request.ajax ? 'layout_blank.html.twig' : 'layout_default.html.twig' %}

{% import 'macro_functions.html.twig' as mf %}

{% block meta_title %}{{ 'System activity'|trans }}{% endblock %}

{% set active_menu = 'activity' %}

{% block content %}
<div class="card overflow-auto">
    <div class="card-header">
        <h3 class="card-title">{{ 'System activity'|trans }}</h3>
        <div class="card-actions">
            {{ include('partial_search_action.html.twig') }}
        </div>
    </div>

    <table class="table card-table table-vcenter table-striped text-nowrap sortable">
        <thead>
            <tr>
                <th class="w-1 no-sort">
                    <input class="form-check-input m-0 align-middle batch-delete-master-checkbox" type="checkbox">
                </th>
                <th class="w-1 no-sort"></th>
                <th>{{ 'User'|trans }}</th>
                <th>{{ 'Message'|trans }}</th>
                <th>{{ 'IP'|trans }}</th>
                <th>{{ 'Country'|trans }}</th>
                <th>{{ 'Date'|trans }}</th>
                <th class="w-1"></th>
            </tr>
        </thead>
        <tbody>
        {% set events = admin.activity_log_get_list({ 'per_page': 30, 'page': request.page }|merge(request)) %}
        {% for i, event in events.list %}
        <tr>
            <td>
                <input class="form-check-input m-0 align-middle batch-delete-checkbox" type="checkbox" data-item-id="{{ event.id }}">
            </td>
            <td>
                {% if event.client %}
                <a href="{{ 'client/manage'|alink }}/{{ event.client.id }}">
                    <span class="avatar avatar-sm d-none d-md-inline-block" style="background-image: url({{ event.client.email|gravatar }}&size=20)"></span>
                </a>
                {% elseif event.staff %}
                <a href="{{ 'staff/manage'|alink }}/{{ event.staff.id }}">
                    <span class="avatar avatar-sm d-none d-md-inline-block" style="background-image: url({{ event.staff.email|gravatar }}&size=24)"></span>
                </a>
                {% else %}
                &nbsp;
                {% endif %}
            </td>
            <td>
                {% if event.client %}
                <a href="{{ 'client/manage'|alink }}/{{ event.client.id }}">{{ event.client.name }}</a>
                {% elseif event.staff %}
                <a href="{{ 'staff/manage'|alink }}/{{ event.staff.id }}">{{ event.staff.name }}</a>
                {% else %}
                Guest
                {% endif %}
            </td>
            <td>{{ event.message }}</td>
            <td>{{ event.ip|iplookup }}</td>
            <td>{{ event.ip|ipcountryname|default('Unknown'|trans) }}</td>
            <td>{{ event.created_at|format_datetime }}</td>
            <td>
                <a class="btn btn-icon api-link"
                    href="{{ 'api/admin/activity/log_delete'|link({ 'id': event.id, 'CSRFToken': CSRFToken }) }}"
                    data-api-confirm="{{ 'Are you sure?'|trans }}"
                    data-api-redirect="{{ 'activity'|alink }}">
                    <svg class="icon">
                        <use xlink:href="#delete" />
                    </svg>
                </a>
            </td>
        </tr>
        {% else %}
        <tr>
            <td colspan="6">{{ 'The list is empty'|trans }}</td>
        </tr>
        {% endfor %}
        </tbody>
    </table>

    <div class="card-footer d-flex align-items-center justify-content-between">
        {{ include('partial_batch_delete.html.twig', { 'action': 'admin/activity/batch_delete' }) }}
        {{ include('partial_pagination.html.twig', { 'list': events, 'url': 'activity' }) }}
    </div>
</div>
{% endblock %}
