@extends('layouts.admin')

@section('title', 'Historique du Modèle')
@section('page_title', 'Historique de Modifications')

@section('content')
<div class="container-fluid">
    <div class="row">
        <div class="col-12">
            <div class="card">
                <div class="card-header">
                    <h5 class="card-title">Historique des Modifications</h5>
                </div>
                <div class="card-body">
                    <div class="alert alert-info">
                        <strong>Modèle :</strong> {{ $model ?? 'N/A' }} | 
                        <strong>ID :</strong> {{ $modelId ?? 'N/A' }}
                    </div>

                    <div class="table-responsive">
                        <table class="table table-striped">
                            <thead>
                                <tr>
                                    <th>Date</th>
                                    <th>Utilisateur</th>
                                    <th>Action</th>
                                    <th>Modifications</th>
                                </tr>
                            </thead>
                            <tbody>
                                @forelse($logs ?? [] as $log)
                                    <tr>
                                        <td>{{ $log->created_at->format('d/m/Y H:i') }}</td>
                                        <td>{{ $log->user->name ?? 'N/A' }}</td>
                                        <td>
                                            <span class="badge bg-primary">{{ $log->event ?? 'N/A' }}</span>
                                        </td>
                                        <td>
                                            <small class="text-muted">
                                                {{ count($log->new_values ?? []) }} champ(s) modifié(s)
                                            </small>
                                        </td>
                                    </tr>
                                @empty
                                    <tr>
                                        <td colspan="4" class="text-center text-muted">
                                            Aucune modification enregistrée
                                        </td>
                                    </tr>
                                @endforelse
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
@endsection
