@extends('layouts.admin', ['title' => 'Audit Logs | Admin'])

@section('content')
    <section class="lc-page-shell">
        <div class="section-heading">
            <div>
                <span>Audit</span>
                <h1>سجل التدقيق</h1>
            </div>
            <a class="secondary-button" href="{{ route('admin.dashboard') }}">لوحة الإدارة</a>
        </div>

        <form class="surface mt-6 flex flex-col gap-3 p-4 md:flex-row" action="{{ route('admin.audit-logs.index') }}">
            <label class="form-field flex-1">
                <span>بحث بالعملية</span>
                <input name="action" value="{{ $action }}" placeholder="voucher / referral / wallet">
            </label>
            <button class="primary-button self-end" type="submit">بحث</button>
        </form>

        <div class="surface mt-5 overflow-hidden p-5">
            <div class="overflow-hidden rounded-2xl border border-[#e0e8e3]">
                @forelse($logs as $log)
                    <div class="grid gap-3 border-b border-[#e0e8e3] p-4 md:grid-cols-[220px_1fr_220px]">
                        <div>
                            <strong class="block text-[#17264d]">{{ $log->action }}</strong>
                            <span class="text-xs text-[#6e7488]">{{ $log->created_at->format('Y-m-d H:i:s') }}</span>
                        </div>
                        <div class="text-sm text-[#6e7488]">
                            <span class="block">Subject: {{ class_basename($log->subject_type) ?: '-' }} #{{ $log->subject_id }}</span>
                            @if($log->metadata)
                                <code class="mt-2 block whitespace-pre-wrap rounded-xl bg-[#f7f8fb] p-3 text-xs text-[#17264d]">{{ json_encode($log->metadata, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT) }}</code>
                            @endif
                        </div>
                        <div class="text-sm">
                            <strong class="block text-[#17264d]">{{ $log->actor?->email ?? 'System' }}</strong>
                            <span class="text-[#6e7488]">{{ $log->ip_address }}</span>
                        </div>
                    </div>
                @empty
                    <div class="p-5 text-sm text-[#6e7488]">لا توجد سجلات بعد.</div>
                @endforelse
            </div>
            <div class="mt-4">{{ $logs->links() }}</div>
        </div>
    </section>
@endsection
