@extends('layouts.yellow')


@section('content')
<style>
       .badge-primary {
    color: #fff;
    background-color: #007bff;
}
.badge-secondary {
    color: #fff;
    background-color: #6c757d;
}

.badge-success {
    color: #fff;
    background-color: #28a745;
}

.badge-danger {
    color: #fff;
    background-color: #dc3545;
}

.badge-pill {
    padding-right: .6em;
    padding-left: .6em;
    border-radius: 10rem;
}   

.badge-warning {
    color: #212529;
    background-color: #ffc107;
}

.badge-info {
    color: #fff;
    background-color: #17a2b8;
}

.badge-light {
    color: #212529;
    background-color: #f8f9fa;
}

.badge-dark {
    color: #fff;
    background-color: #343a40;
}
</style>
<div class="container-fluid">
    <div class="card">
        <div class="card-header bg-primary text-white"  style="color: white !important;">
            <div class="d-flex justify-content-between align-items-center">
                <h3>Detalle de Auditoría #{{ $audit->id }}</h3>
                <a href="{{ route('admin.audits.index') }}" class="btn btn-light">Volver a la lista</a>
            </div>
        </div>
        <div class="card-body">
            <div class="row">
                <div class="col-md-6">
                    <table class="table table-bordered">
                        <tr>
                            <th>ID:</th>
                            <td>{{ $audit->id }}</td>
                        </tr>
                        <tr>
                            <th>Usuario:</th>
                            <td>{{ $audit->user ? $audit->user->name : 'Sistema' }}</td>
                        </tr>
                        <tr>
                            <th>Acción:</th>
                            <td>
                                @switch($audit->action)
                                    @case('create')
                                        <span class="badge badge-success">Crear</span>
                                        @break
                                    @case('update')
                                        <span class="badge badge-warning">Actualizar</span>
                                        @break
                                    @case('delete')
                                        <span class="badge badge-danger">Eliminar</span>
                                        @break
                                    @case('login')
                                        <span class="badge badge-info">Inicio de sesión</span>
                                        @break
                                    @case('logout')
                                        <span class="badge badge-secondary">Cierre de sesión</span>
                                        @break
                                    @default
                                        <span class="badge badge-primary">{{ $audit->action }}</span>
                                @endswitch
                            </td>
                        </tr>
                        <tr>
                            <th>Modelo:</th>
                            <td>{{ class_basename($audit->model) }}</td>
                        </tr>
                        <tr>
                            <th>ID Registro:</th>
                            <td>{{ $audit->model_id }}</td>
                        </tr>
                    </table>
                </div>
                <div class="col-md-6">
                    <table class="table table-bordered">
                        <tr>
                            <th>Fecha y Hora:</th>
                            <td>{{ $audit->created_at->format('d/m/Y H:i:s') }}</td>
                        </tr>
                        <tr>
                            <th>Dirección IP:</th>
                            <td>{{ $audit->ip }}</td>
                        </tr>
                        <tr>
                            <th>URL:</th>
                            <td>{{ $audit->url }}</td>
                        </tr>
                        <tr>
                            <th>Método:</th>
                            <td>{{ $audit->method }}</td>
                        </tr>
                        <tr>
                            <th>Navegador:</th>
                            <td>{{ $audit->user_agent }}</td>
                        </tr>
                    </table>
                </div>
            </div>

            @if($audit->old_values || $audit->new_values)
            <div class="row mt-4">
                <div class="col-12">
                    <h4>Valores modificados</h4>
                    <table class="table table-striped table-bordered">
                        <thead>
                            <tr>
                                <th>Campo</th>
                                <th>Valor Anterior</th>
                                <th>Valor Nuevo</th>
                            </tr>
                        </thead>
                        <tbody>
                            @if($audit->action == 'create')
                                @foreach($audit->new_values as $field => $value)
                                <tr>
                                    <td>{{ $field }}</td>
                                    <td><i>No existe</i></td>
                                    <td>
                                        @if(is_array($value))
                                            <pre>{{ json_encode($value, JSON_PRETTY_PRINT) }}</pre>
                                        @else
                                            {{ $value }}
                                        @endif
                                    </td>
                                </tr>
                                @endforeach
                            @elseif($audit->action == 'delete')
                                @foreach($audit->old_values as $field => $value)
                                <tr>
                                    <td>{{ $field }}</td>
                                    <td>
                                        @if(is_array($value))
                                            <pre>{{ json_encode($value, JSON_PRETTY_PRINT) }}</pre>
                                        @else
                                            {{ $value }}
                                        @endif
                                    </td>
                                    <td><i>Eliminado</i></td>
                                </tr>
                                @endforeach
                            @elseif($audit->action == 'update')
                                @foreach($audit->new_values as $field => $value)
                                <tr>
                                    <td>{{ $field }}</td>
                                    <td>
                                        @if(isset($audit->old_values[$field]))
                                            @if(is_array($audit->old_values[$field]))
                                                <pre>{{ json_encode($audit->old_values[$field], JSON_PRETTY_PRINT) }}</pre>
                                            @else
                                                {{ $audit->old_values[$field] }}
                                            @endif
                                        @else
                                            <i>No disponible</i>
                                        @endif
                                    </td>
                                    <td>
                                        @if(is_array($value))
                                            <pre>{{ json_encode($value, JSON_PRETTY_PRINT) }}</pre>
                                        @else
                                            {{ $value }}
                                        @endif
                                    </td>
                                </tr>
                                @endforeach
                            @endif
                        </tbody>
                    </table>
                </div>
            </div>
            @endif
        </div>
    </div>
</div>
@endsection 