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

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

{% block meta_title %}{{ 'Clients login history'|trans }}{% endblock %}

{% set active_menu = 'activity' %}

{% block content %}
<div class="card overflow-auto">
    <div class="card-body">
        <h5>{{ 'Client login history'|trans }}</h5>
    </div>

    {{ include('partial_search.html.twig') }}
    <table class="table card-table table-vcenter table-striped text-nowrap">
        <thead>
            <tr>
                <th class="w-1">
                    <input class="form-check-input m-0 align-middle batch-delete-master-checkbox" type="checkbox">
                </th>
                <th class="w-1"></th>
                <th>{{ 'User'|trans }}</th>
                <th>{{ 'IP'|trans }}</th>
                <th>{{ 'Country'|trans }}</th>
                <th>{{ 'Date'|trans }}</th>
                <th class="w-1"></th>
            </tr>
        </thead>

        <tbody>
        {% set history = admin.client_login_history_get_list({ 'per_page': 30, 'page': request.page }|merge(request)) %}
        {% for i, event in history.list %}
        <tr>
            <td>
                <input class="form-check-input m-0 align-middle batch-delete-checkbox" type="checkbox" data-item-id="{{ event.id }}">
            </td>
            <td>
                <a href="{{ 'client/manage'|alink }}/{{ event.client.id }}">
                    <span class="avatar avatar-xs d-none d-md-inline-block" style="background-image: url({{ event.client.email|gravatar }}&size=24)"></span>
                </a>
            </td>
            <td>
                <a href="{{ 'client/manage'|alink }}/{{ event.client.id }}">{{ event.client.first_name }} {{ event.client.last_name }}</a>
            </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/client/login_history_delete'|link({ 'id': event.id, 'CSRFToken': CSRFToken }) }}"
                    data-api-confirm="{{ 'Are you sure?'|trans }}"
                    data-api-redirect="{{ 'client/logins'|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/client/batch_delete_log' }) }}
        {{ include('partial_pagination.html.twig', { 'list': history, 'url': 'client/logins' }) }}
    </div>
</div>
{% endblock %}
