@extends('layouts.admin')

@section('title', "Journal d'activite")

@php
    $breadcrumbs = [['label' => "Journal d'activite"]];
@endphp

@section('content')

    <div class="mb-5 flex flex-col gap-1">
        <h1 class="text-xl font-bold text-brand-ink">Journal d'activite</h1>
        <p class="text-sm text-brand-muted">{{ count($activity) }} entree(s) journalisee(s).</p>
    </div>

    <div class="admin-card overflow-hidden">
        <x-admin.list-toolbar search-placeholder="Rechercher dans le journal...">
            <select class="admin-field-input sm:w-44" aria-label="Filtrer par action">
                <option>Toutes les actions</option>
                <option>Connexion</option>
                <option>Creation</option>
                <option>Modification</option>
                <option>Archivage</option>
                <option>Consultation</option>
            </select>
        </x-admin.list-toolbar>

        <div class="overflow-x-auto">
            <table class="admin-table">
                <thead>
                    <tr>
                        <th>Utilisateur</th>
                        <th>Action</th>
                        <th>Ressource</th>
                        <th>Date</th>
                        <th>Adresse IP</th>
                        <th>Resultat</th>
                        <th class="text-right">Detail</th>
                    </tr>
                </thead>
                <tbody>
                    @forelse ($activity as $entry)
                        <tr>
                            <td class="font-medium text-brand-ink">{{ $entry['user'] }}</td>
                            <td class="text-brand-muted">{{ $entry['action'] }}</td>
                            <td class="text-brand-muted">{{ $entry['resource'] }}</td>
                            <td class="text-xs text-brand-muted">{{ $entry['date_demo'] }}</td>
                            <td class="font-mono text-xs text-brand-muted">{{ $entry['ip_demo'] }}</td>
                            <td><x-admin.status-badge :status="$entry['result']" /></td>
                            <td class="text-right">
                                <button type="button" data-modal-open="activity-detail-{{ $entry['id'] }}" class="btn btn-ghost btn-sm">Details</button>
                            </td>
                        </tr>
                    @empty
                        <tr>
                            <td colspan="7" class="py-8 text-center text-sm text-brand-muted">Aucune activite enregistree.</td>
                        </tr>
                    @endforelse
                </tbody>
            </table>
        </div>
        <x-admin.pagination :current-page="1" :total-pages="1" :total-items="count($activity)" />
    </div>

    @foreach ($activity as $entry)
        <x-admin.modal :id="'activity-detail-' . $entry['id']" title="Detail de l'entree">
            <dl class="grid grid-cols-2 gap-x-4 gap-y-2 text-sm">
                <dt class="text-brand-muted">Utilisateur</dt><dd class="text-brand-ink">{{ $entry['user'] }}</dd>
                <dt class="text-brand-muted">Action</dt><dd class="text-brand-ink">{{ $entry['action'] }}</dd>
                <dt class="text-brand-muted">Ressource</dt><dd class="text-brand-ink">{{ $entry['resource'] }}</dd>
                <dt class="text-brand-muted">Description</dt><dd class="text-brand-ink">{{ $entry['description'] }}</dd>
                <dt class="text-brand-muted">Date</dt><dd class="text-brand-ink">{{ $entry['date_demo'] }}</dd>
                <dt class="text-brand-muted">Adresse IP</dt><dd class="font-mono text-brand-ink">{{ $entry['ip_demo'] }}</dd>
                <dt class="text-brand-muted">Resultat</dt><dd><x-admin.status-badge :status="$entry['result']" /></dd>
            </dl>
        </x-admin.modal>
    @endforeach

@endsection
