@extends('layouts.admin')

@section('title', 'Activités de ' . $user->name)
@section('page-title', 'Activités de ' . $user->name)

@section('content')
<div class="row mb-4">
    <div class="col-md-3">
        <div class="card border-0 shadow-sm">
            <div class="card-body text-center">
                <h6 class="text-muted mb-1">Actions totales</h6>
                <h2 class="mb-0">{{ number_format($stats['total_actions']) }}</h2>
            </div>
        </div>
    </div>
    <div class="col-md-3">
        <div class="card border-0 shadow-sm">
            <div class="card-body text-center">
                <h6 class="text-muted mb-1">Connexions</h6>
                <h2 class="mb-0">{{ number_format($stats['logins_count']) }}</h2>
            </div>
        </div>
    </div>
    <div class="col-md-3">
        <div class="card border-0 shadow-sm">
            <div class="card-body text-center">
                <h6 class="text-muted mb-1">Ce mois</h6>
                <h2 class="mb-0">{{ number_format($stats['actions_this_month']) }}</h2>
            </div>
        </div>
    </div>
    <div class="col-md-3">
        <div class="card border-0 shadow-sm">
            <div class="card-body text-center">
                <h6 class="text-muted mb-1">Dernière connexion</h6>
                <p class="mb-0">{{ $stats['last_login'] ? $stats['last_login']->format('d/m/Y H:i') : '-' }}</p>
            </div>
        </div>
    </div>
</div>

<div class="card">
    <div class="card-header bg-white d-flex justify-content-between align-items-center">
        <div>
            <h5 class="mb-0">{{ $user->name }}</h5>
            <small class="text-muted">{{ $user->email }}</small>
        </div>
        <a href="{{ route('admin.activity-logs.index') }}" class="btn btn-outline-secondary btn-sm">
            <i class="bi bi-arrow-left me-1"></i> Retour
        </a>
    </div>
    <div class="card-body">
        @if($logs->isEmpty())
            <div class="text-center py-5 text-muted">
                <i class="bi bi-activity fs-1 d-block mb-3"></i>
                <p>Aucune activité pour cet utilisateur</p>
            </div>
        @else
            <div class="table-responsive">
                <table class="table table-hover">
                    <thead>
                        <tr>
                            <th>Date/Heure</th>
                            <th>Action</th>
                            <th>Description</th>
                            <th>IP</th>
                        </tr>
                    </thead>
                    <tbody>
                        @foreach($logs as $log)
                        <tr>
                            <td>{{ $log->created_at->format('d/m/Y H:i:s') }}</td>
                            <td>
                                @php
                                    $badgeClass = match($log->action) {
                                        'login' => 'bg-success',
                                        'logout' => 'bg-secondary',
                                        'create' => 'bg-primary',
                                        'update' => 'bg-info',
                                        'delete' => 'bg-danger',
                                        'export' => 'bg-warning',
                                        default => 'bg-secondary'
                                    };
                                @endphp
                                <span class="badge {{ $badgeClass }}">{{ $log->action_label ?? ucfirst($log->action) }}</span>
                            </td>
                            <td><small>{{ $log->description ?? '-' }}</small></td>
                            <td><code class="small">{{ $log->ip_address ?? '-' }}</code></td>
                        </tr>
                        @endforeach
                    </tbody>
                </table>
            </div>
            <div class="mt-3">
                {{ $logs->links() }}
            </div>
        @endif
    </div>
</div>
@endsection
