@extends('super-admin.layout')

@section('title', 'Audit log')

@section('content')
<div class="pg-head">
    <div>
        <h1>Audit log</h1>
        <p>Immutable record of Super Admin actions on the platform.</p>
    </div>
</div>

<div class="card section-card" style="margin-bottom:1rem">
    <form method="GET" class="d-flex flex-wrap gap-2 align-items-center">
        <input type="search" name="q" class="form-input" style="max-width:200px" placeholder="Entity ID, action…" value="{{ $q }}">
        <select name="action" class="form-input" style="max-width:200px">
            <option value="">All actions</option>
            @foreach($actions as $act)
                <option value="{{ $act }}" @selected($action === $act)>{{ $act }}</option>
            @endforeach
        </select>
        <input type="text" name="entity" class="form-input" style="max-width:180px" placeholder="Entity type" value="{{ $entity }}">
        <button type="submit" class="btn-outline btn-sm">Filter</button>
    </form>
</div>

<div class="card">
    <div class="tbl-wrap">
        <table class="data-tbl">
            <thead>
                <tr>
                    <th>When</th>
                    <th>Admin</th>
                    <th>Action</th>
                    <th>Entity</th>
                    <th>Details</th>
                </tr>
            </thead>
            <tbody>
                @forelse($logs as $log)
                    <tr>
                        <td class="cell-sub">{{ $log->created_at?->format('d M Y, H:i') }}</td>
                        <td>{{ $log->admin?->name ?? 'System' }}</td>
                        <td class="mono">{{ $log->action }}</td>
                        <td class="cell-sub">
                            @if($log->entity_type)
                                {{ class_basename($log->entity_type) }}<br>
                                <span class="mono">{{ $log->entity_id }}</span>
                            @else
                                -
                            @endif
                        </td>
                        <td class="cell-sub" style="max-width:280px">
                            @if($log->new_values)
                                {{ json_encode($log->new_values, JSON_UNESCAPED_UNICODE) }}
                            @else
                                -
                            @endif
                        </td>
                    </tr>
                @empty
                    <tr><td colspan="5" class="text-center cell-sub py-4">No audit entries yet.</td></tr>
                @endforelse
            </tbody>
        </table>
    </div>
</div>
@endsection
